S40 gas pedal problem

2006 Volvo s40 68k miles.

2 weeks ago the battery was replaced. The following day the ?Check Engine Systems? warning light went on. The car was at a stoplight, and would not accelerate. Stomped hard on the gas, it lurched forward and accelerated. This happened several times over the weekend.

Took the car to the dealership, followed recommendation and Replaced gas pedal. On the way home from the dealership it happened again? except this time I was driving about 50mph and the car decelerated. Pressed the gas pedal all of the way to the floor, car lurched and started working again. (same warning message.)

Returned to dealership. Computer says ?needs new gas pedal?. Dealership is stumped. Either I got a lemon of a replacement gas pedal or they have no idea. Either way they need to recreate the problem. The car is not cooperating and is running fine.

Any ideas???