I believe you will want to keep the 2002 PCM in that 2002 truck.
Two things come to mind. The 2004 should have the secondary AIR system I believe. You need to take that off the 2004 engine and use the blockoff plate from the 2002 engine to block the port on the 2004 engine.
I assume you kept the 2002 rear axle in the 2002. The PCM has the gear ratios programmed into them and cannot be changed by any tuner or reflash or whatever. So you need the rear axle and PCM to match. Keep the same 2002 PCM and rear axle from the 2002.
A couple other things I am not sure of...
The fuel system. The 2002 has a two pipe system, supply and return. At some point they changed to a one pipe system (no return line). If the 2004 has a one pipe system you will need to swap your 2002 two pipe fuel rail over the the 2004 engine.
Coolant temp sensor location: the 2002 sensor is at front left of engine by the thermostat. At some point it was relocated to the passenger side rear somewhere. You might have to extend the sensor wiring if the two are different, 2002 vs 2004.