HI!
I have a 2004 Z4 2.5 Litre which I got really cheap off ebay.
My symptoms were the car is fine up until you exceed 3,000 rpm which without fail would send it into limp mode - Accompanied by various warning lights - Engine Block / EML / Tyre Pressure / ABS in fact nearly of them together with failing power steering and headlights.
Sometimes you could get it up to 4,500rpm in 2nd gear before it did all of this.
Then you switch off & restart immediately (No need to wait) and everything's OK with all warning lights gone out.
As long as you stay on low revs and everything was fine....
As a matter of course I replaced the Crank Sensor (New Item), Inlet Cam Sensor (New Item), MAF Sensor (Used Item) Oil & Filter, did an Injector clean and Throttle body clean (Spray Carb Cleaner into the Air intake. NOTE - MAF sensor must be removed as carb cleaner could leave a residue on it), Idle control valve remove /test / clean. Vanos Inlet solenoid remove clean test, DISA valve remove /clean /test, vacuum test with my Smoke Machine. (See Youtube Videos on how to test them).
None of that fixed the limp mode problem.
Watching further Youtube videos i saw that the throttle body is not controlled by a cable but it responds to a sensor on the accelerator pedal.
What happens is you press the pedal and the computer counts the number of contacts that are made on the pedal position sensor, 1.2.3.4.5 etc. If one of them is dirty then the computer thinks contact number 5 is number 4, number 10 is number 9 etc.
This signal is then sent to the throttle body butterfly and it moves accordingly and the computer takes note of it's position.
Then the computer checks that the throttle body and pedal position are matching - Which they wont be.
The ECU does not like this as it thinks the throttle is stuck open and therefore sends the car into limp mode for safety.
This will only happen when the accelerator goes past that bad point - Which is why i could get 4,500rmp out of it in 2nd gear but 3,000rpm in 4th gear.
So I replaced the Pedal Assembly with a used item (From some BMW Diesel model- but it worked and so it must have the same sensor in there - IE Does not have to be Z4 specific). The sensor in the pedal assembly is not accessible to be cleaned as it has tamper proof bolts. Then I used a YouTube video to reset the throttle pedal (Something like press and hold for 30 seconds).
This did not work - Still Limp Mode over 3,000rpm.
The other culrpit could be the Throttle body, remember the butterfly in there is operated by a motor which responds to a signal from the Pedal via the ECU. There's a collection of what look like clock wheels to move the butterfly all housed in that plastic cover on the side of the Throttle Body assembly. (I'm not sure if that cover is removeable of if these items are serviceable)
So I replaced the Throttle Body for a used item (£GoodPrice) from Bridgend BMW spares / breakers in Pluckley, Kent. (Not sure If I'm allowed to name drop).
Perfect - Problem solved.
In short the car was going into Limp Mode as the computer did not like the fact that the "Carburettor" was not doing what the pedal / driver was telling it to do. The position of the butterfly did not match the drivers request.
This may be caused by the pedal and / or the throttle body.
The throttle body in reasonably easy to replace.
I saw some videos where they took apart the pedal assembly (There are tamper proof bolts on it) cleaned and problem solved.
For me it was the Throttle body - swapping the Pedal Assembly back made no difference.
NOTE - Don't try to push open / closed the throttle butterfly with your fingers. It's meant to be moved only by a motor, if you force it you'll ruin it.