Mine did it too for a while. Turned out to be a knackered TPS. My old 5 also did it and that turned out to be a knackered stepper motor.
Have you tried removing the battery. Leave it for 15 minutes. Plug it back in with all electrics on (eg lights, fans, stereo, air con etc) for 5-10 mins on idle. Then turn all electrics off and let it sit for another 5-10 mins.
^That may not do owt but I was told to do that on another forum.
Disconnect for 1 min is all that's needed.
Idle with no electrics 10 min
Idle with electrics 10 min
Then take for a drive
Correct procedure