Mine was caused by a secondary air pump relay. The dealer told me it was the pump itself. I tested the pump, checked the fuse, and then determined that it was the relay. I changed it 2 months ago and the light went off and hasn't come back on.
If you think its the gas, just go get a bottle of octane booster and take your car for a highway trip and beat on it for a while.
2016 528i Xdrive
2016 M235i 6sp