Sounds like you have a couple of different problems here.
The P0340 is pointing to a fault in the Camshaft Position sensor. When this sensor is faulty, it will cause the symptoms you describe of stalling and hesitating and will set a P0172. So replacing the Camshaft Sensor will cure both the P0340 and the P0172.
The P1484 is actually a "known" problem with these vehicles, and GM has issued a Technical Service Bulletin on the cause and repair of this issue:
Bulletin No.: 05-06-02-012B
Date: October 19, 2006
Service Engine Soon (SES) or Check Engine Light On, DTC P0480/P0526/P1481/P1484 Set (Replace Engine Cooling Fan Wiring Harness)
2004-2006 Buick Rainier
2002-2006 Chevrolet TrailBlazer, TrailBlazer EXT
2002-2006 GMC Envoy, Envoy XL
2004-2005 GMC Envoy XUV
2005-2006 GMC Envoy Denali, Envoy XL Denali
2002-2004 Oldsmobile Bravada
2005-2006 Saab 9-7X
Some customers may comment that the Service Engine Soon (SES) or Check Engine light is illuminated. This condition may be intermittent and upon investigation, the technician may find either DTC P0480, P0526, P1481 or P1484 set.
This condition may be caused by the cooling fan harness chaffing against the plastic guide it routes through. This contact may damage the insulation of the wires enclosed in that harness.
Replace the engine cooling fan harness using the procedure listed below.
Remove the cooling fan.
Place the cooling fan assembly on a bench.
Disconnect the harness electrical connector from the cooling fan clutch.
Remove the harness from the plastic guide while feeding the wires out of the slot.
Before installing the new harness, wrap the affected area on the wires with electrical tape to keep the protective sleeve in place. Be sure to keep the tape approximately 25 mm (1 in) away from the connector so the wires can be fed into the slot.
Feed the wires into the slot and install the harness to the plastic guide.
Connect the harness electrical connector to the cooling fan clutch.
Install the cooling fan.