After some fighting with my phone I came up with a solution.
1. Since the phone said that it was optimizing one app always, I assumed the problem was a single app. Then I deduced that app was Floatifications because it messed up with the phone security settings (for the notifications access) and was the most mod-heavy app I has installed lately. So I tried to uninstall it via ADB.
1.1 I had a second issue that the phone didn't recognized that it was connected to a computer. To circumvent this I booted into fastboot menu and I selected the BP tools option. When the phone booted up again with the service app activated it recognized the USB connection to the computer and turned on debugging mode.
2. I tried different commands to uninstall it via ADB, the one that worked was: adb shell pm uninstall -k <package name>
2.1 In this case of floatifications the whole command is 'adb shell pm uninstall -k robj.floating.notifications'
3. After a reboot everything was working normally. Including the USB connection.
For a final remark, I came up with this whole process by trial and error so maybe there is an easier way of doing all this stuff. I also uninstalled in the same process the lockscreen app "Cover" that also requested access to notifications but I don't think that app was the problem since the phone said it was optimizing one app and it isn't as muddy as Floatifications.