my guess is its the Idle Control Valve, you can usually find these in junkyards for fairly cheap for that engine cause they are fairly common. look around locally for people parting them out, i know that up here in WA we have quite a few bmw's people end up parting. Sign up on your local BMWCCA chapter and post a thread there asking for the part as well. a lot of times there is some guy who has hella parts lyin around and chances are they'll have that as well.
As far as the rattle, get your car up on a lift or jack it up and shake each section of the exhaust or use the old screwdriver to the ear technique in several places. it may not even be the actual pipe, it could likely be a heat shield that's missing a bolt. happened on my old roomates wrx when we changed the turbo.