First check the air intake hose right before the throttle, you will see a little hose branches off to the idle control -it's kind of a harmonic hose - see if it cracked. Most of the times that's causing the problem.
Let me know what you did find and we will go from there.
Zee
RepairPal Certified shops can diagnose and repair your 2002 BMW 530i. They provide transparent pricing with a minimum 12-month or 12,000-mile warranty on repairs and services.