Volvo S60R RPM's drop randomly and gas pedal doesn't work

I have a 2004 volvo s60R (manual transmission) with 27K miles on it. Just last week while I was driving the gas pedal stopped working while driving and the car just coasted to a stop as the rpm’s dropped. About 30 seconds later, the problem disappeared. I brought it into the shop and they said it was a bad fuel pressure sensor, which they replaced. On the way home from the shop, the problem happened again, but near caused an accident. The first thing that happened was at a stoplight at idle the car idled very low (around 500 rpm’s) causing the engine to knock and the whole car to shake. When the light turned green, I’d give it gas from a standstill and the rpm’s would reach about 1500-2000 and then they would platuea and then drop and the car sometimes would then stall. This happened for about 30 seconds and then the car responded again. Two minutes later, it did the same thing and I was stuck for about 10 minutes. It then was ok again long enough for me to drive back to the dealership shop and drop it off. It’s there now and they’re trying to diagnose it. Any advice anyone? Thanks.