All the usual disclaimers apply . . in short, do this at your own risk, blah blah blah. Also, people have different methods of doing this job, and I have mine.
This writeup is for an E36 M50 engine, but others will be very similar in execution.
Rough idling can mean your Idle Control Valve is dirty and sticking. This should take under an hour to do, and requires minimal tools. It will, however take some patience because the hoses are a pain the ass to get off, given the cramped quarters you'll be working in. Most of the work involves moving some stuff out of the way so you can reach the ICV. My apologies to those of you with unusually large arms or hands . . you may have to do it the hard way by removing the intake manifold, which is not part of the scope of this DIY
Start by removing the alternator cooling duct (blue arrows).
Next, remove the intake air temperature sensor at the back of the airbox by unscrewing the 10mm bolt.
At the front of the airbox, disconnect the air intake duct.
Unscrew the two 10mm bolts that secure the airbox and cruise control unit (blue arrows).
At the back of the airbox, unclip the mass airflow sensor (clips shown by arrows).
Disconnect the mass airflow sensor at the opposite end, and move it to the side and out of the way. Now you will have enough room to get your arms under the intake manifold to reach the ICV. Note the hose indicated by the arrow. This is one of the two hoses that connects to the ICV. Unplug it at the location shown in photo.
Here's a (not so good) photo of where the ICV is located. Remove the wire plug at the front. Feel for a wire clip, and squeeze it in while you pull the plug off the ICV.
Here is a photo of the ICV removed. The hose on the right is the one you disconnected two steps ago. The one on the left connects to the intake manifold. Rather than removing the hoses at the ICV, it's easier to do it at the opposite ends, since there is no room to grab them with enough force at the ICV's location. Also note the type of hose clamp that is used in the photo . . you'll never get that off while it's under the intake manifold! The hoses do
turn around the ICV openings, so spin them as you see fit in order to get the whole thing out from under the manifold.
Photo of the dirt and crud inside. Arrow points to the valve (or 'door') that controls the airflow at idle. Use rubbing alcohol, a toothbrush and q-tips to clean both openings well. Open and close the valve while you clean. Also pour the alcohol in there, slush it around, drain, and repeat. Let dry for about 10min, then spray some WD40 in there, and work the valve to get it moving smoothly.
Here's a photo of a cleaned ICV. Now put everything back in reverse order, and you're done!