I'd start with a thorough check for vacuum leaks, then move on to the idle control valve:
https://www.youtube.com/watch?v=ePXODqkfIvI
2002 X5 3.0 347,000 miles
2014 428i 39,000 miles
2004 325i sold at 123,600 miles
2001 325i sold at 66,000 miles
1970 Firebird Under restoration - time for paint