I had that problem once. What I did was:
1. Backup apps using Titanium Backup (root required).
2. Removed External SD Card.
3. Rebooted into "Download" mode.
4. Flashed a stock .tar.md5 for my device (which is the SM-G900AZ) using Odin 3.09. You can find YOUR stock Firmware at Sammobile.com If the SD Card is still inserted, after the Firmware Flashing process has complete, booting into "Download" mode will still show CUSTOM.
5. Booted into a FRESH STOCK OEM ROM. Accepted the OTA, and it flashed using stock recovery (note I still haven't put the SD Card back in).
6. Once installed I turned the device off, inserted the SD Card, and booted into my ROM.
7. Restored apps by using Titanium Backup (root required).
Also know that I use custom ROMs, so usually root is retained because the exploit/SuperSU is built in. If you are going through A MAJOR OTA, it may patch ALL vulnerabilities to obtain root, if that's your cup of tea. I done the research and found out before that if I HAD taken an OTA I was wanting, I would've lost the ability to loose all my "goodies" for what was 3 months. So I opted to take and AOSP updated ROM instead, 😂