I'm not familiar with the 5 series, mines a 3 series E46, but I had a very similar problem. Mine turned out to be a faulty mass airflow sensor (MAF) that on the 3 series is immediately after the air filter.
I'd gone through a lot of other checks first. Checking there's fuel getting through (after the engine has stalled take the cover off the little nozzle on the fuel rail and press down on the valve - it's like the tyre valve - but keep your head out of the way. If there is enough fuel getting through it will spurt out under high pressure - if not there may be a problem with the pump / fuel filter not getting enough fuel to the engine. All that's assuming the 5 series has a fuel rail like mine etc)
My service was also due so I replaced the spark plugs, air filter etc as they had to be done anyway. Eventually I bought a kit to read the codes from the car's computer and that identified the MAF as the problem.
It was already on the list of things to try but as they are very expensive I didn't want to buy one on the off chance. p.s. buy the proper BMW part. I bought a cheaper 3rd party one and that didn't work leading me to think it wasn't the MAF and calling in the garage for a tow and repair. They put a BMW one on and fixed it.