I have just resolved this exact problem on my 1990 240. Its the Speedo, believe it or not!
After a decent drive at highway speeds, 45 minutes or so, the engine would idle at about 1500RPM. After switching off and immediately restarting, it idled fine. Short drives did not set the problem off.
The giveaway was the restarting - normal idle. A quick reset solved the problem until next time. So I t is not a mechanical issue.
If you flash out the codes, you will probably get code 311: Vehicle Speed Signal missing.
On these cars, the speedo is connected to the ECU and tells it if the car is moving or not. If that is missing, then after a while, the ECU goes into a sort of limping mode and idles high.
Pin 34 on the ECU should be connected to pin 6 on the rear of the instrument cluster. Pin 6 delivers the "taxi signal " from the speedo to the ECU. That signal can be missing for several reasons.
The most common seems to be that someone connected the tach wire to the wrong pin on the rear of the cluster and fried the UAF 2115 chip in the speedo. The speedo will probably still work but there is no signal for the ECU. The chip is cheap to buy on eBay and not hard to replace.
I replaced mine but still had the fault code and bad idle. (I fixed the odometer while I was at it)
I eventually noticed that my 1990 car actually had a 1987 cluster in it. Pin six in 1987 has something to do with the A/C relay. it does not carry the Taxi signal. So I pulled the cluster apart again, and found that the appropriate pin on the actual speedo is connected to a totally different pin on the back of the cluster. I cut the Black/Blue wire off pin 6 and routed it to the correct pin.
Problem solved.
I also had an ICU code 144: Load signal missing. It has now vanished. Perhaps the ECU needed vehicle speed to provide load signal to the ICU?? I'm not sure on this, but both codes are now gone and car runs well. (ICU was running the engine heavily retarded with no load signal as without the signal it was assuming full load.)
Below is some links and pics:
https://www.volvo-forums.com/threads/fault-311-code-and-idle-problems.40451/
How to flash codes:
https://www.volvoclub.org.uk/faq/EngineOBDCodes.html#FuelInjectionandIgnitionDiagnosticCodesi
This web site is hard to find stuff on but has fantastic information:
https://www.prancingmoose.com/240-odometer-repair.html
This is what I should have in my car: Note plug 31, pin 6.
This is what I actually have:
This is an electronic speedo. the Vehicle speed signal is provided by the very far right pin labeled VSS to ECU. That pin can be probed on the very rear of the cluster without dismantling the cluster. Immediately above pin 233, which is the speedo conection, on the cluster circuit board, are three tiny little copper nubs. two conect to the strip fuse and the third, the very top one is the VSS signal that is supposed to go to the ECU. (it also runs the factory cruise control) I found that on the '87 cluster, it is wired directly to pin 200 . i just cut the wire off round plug pin 6 and put it on pin 200.