Welcome to 2CarPros.
It sounds like an issue with the idle speed control valve. I will supply the directions for replacing it, but before replacing it, check it for carbon build up or corrosion that can cause it to not function properly. The attached pictures correlate with the directions.
2006 BMW Z4 3.0si Roadster (E85) L6-3.0L (N52)
Vehicle Powertrain Management Fuel Delivery and Air Induction Idle Speed/Throttle Actuator - Electronic Service and Repair Procedures
Replacing idle speed control valve (M52TU, M54)
Turn off ignition.
Follow instructions for disconnecting and connecting battery. Disconnect battery negative lead.
Remove intake filter housing.
Pull Bowden cable upwards out of holder (1) and suspend from throttle.
Release hose clamps (1).
Detach intake hose piece from throttle assembly and idle-speed control valve.
To facilitate installation, fit air-mass flow sensor with intake hose (1). Coat intake hose (1) with antiseize agent.
Remove intake hose completely (between intake filter housing and throttle assembly).
M52TU and M54:
Disconnect following plug connections:
1 - Resonance flap
2 - Idle-speed control valve
Idle actuator (2) is fitted below intake air manifold, directly above throttle (1).
Release screw (1) on cable duct mounting.
Release screws (2) on holder of idle actuator (3).
Remove idle actuator valve with holder from intake air manifold.
Detach idle actuator (2) from rubber retainer (4).
Always replace gasket (1) from idle actuator (2) to intake air manifold. However, during reinstallation, do not fit gasket on idle actuator but install first in intake air manifold.
Replace gasket (1). To facilitate installation of idle actuator, coat inside of gasket with antiseize agent.
Let me know what you find or if you have other questions.
Images (Click to enlarge)
Saturday, August 31st, 2019 AT 9:09 PM