1995 Mazda b4000

Description of Problem: 1995 Mazda b4000 v6 4×4 rough idle to the point where engine jumps but does not shut off when the accelerator is pushed the problem stops it only happens accelerator is not pressed. At stop lights in park etc. Replaced throttle position sensor and egr pressure sensor and the problem still persists. Could this be the egr valve causing this? Check engine light codes read p0402 p1121 p0102 p0174 p0171