Yep I'm with Dave.... throttle body mechanical and electrical, idle control valve, notorious for sticking and throttle potentiometer/s. Unfortunately the throttle set up has only two sensors and these are well known to have odd behaviour patterns, next time switch the engine off and restart, if normal its the throttle . later vehicles of most marks upgraded to three which produces a more consistent function.
Also have you or anyone else recently disconnected the ducting to the throttle body, if so it may have been overtightened which can lead to air ingress around the butterfly and cause the idle control valve to behave strangely. The ECU thinks you have applied throttle and raises the revs to either hold at that perceived throttle position or in preparation to drive.
Ask Richard V6 as he has recently had such issues he also has a metal bodied throttle body now installed.