With my '92 535I they had a common problem with the check valve for the fuel pump. (Hard to re-start after a quick shut down.) Solution is to replace the check valve.
It could also be the fuel pump, fuel filter(s), or even the injectors.
Try some fuel injector cleaner to see if that helps with the surging. Hopefully that's it.
But it doesn't seem so with the car throwing codes.
Damn computers.