As Mario stated, the problem might be the airflow sensor pot. It is located on the front side of the airflow sensor body with three wires going to it. There is a wiper arm and semiconductor printed circuit board that sends the airflow plate position information to the ECU. The pot gets worn out, especially in the idle range area, and causes erratic idle, surging and stalling.
I replace the one in my '88 260e and it idles perfect now. I purchased the part from Olyparts.com for about $75 and saved the cost of a new airflow sensor.
Hope this helps,