Stalling

1998 BMW 540i started stalling at idle.
First time was after filling up with gasoline. The car restarted after two attempts to start then it kept stalling. Okay for a couple of weeks.
Then the auto glass people plugged something into my cigarette lighter and it drained the battery. The had to jump start the car. Later the car stalled while coasting downhill into a parking lot. I took it to the shop.
The mechanic scanned the codes and found a sensor that was “borderline” weak. They replaced the sensor. The next day the car stalled while waiting at a stop light. The car restarted okay after two attempts.
Later the same day the car stalled at another light, downhill again. This time the car didn’t restart after three attempts. Fourth attempt I gave it a lot of gas to keep it going. It fires up okay, but stalls.
The mechanic checked the wiring to the replaced sensor, but couldn’t find anything.
The car stalled again going uphill out of a parking garage. It restarted and This Time the SERVICE ENGINE SOON light stayed illuminated.

Any ideas, since the codes are not showing the problem?

Thanks.

Check the idle air controller (IAC). If it’s not functioning properly, when teh engine idles back down, it won’t give the throttle that little kick to keep it running, or hold it at the right idle speed.