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
Subject:Service Engine Soon (SES) or Check Engine Light On, DTC P0480/P0526/P1481/P1484 Set (Replace Engine Cooling Fan Wiring Harness)
Models:2004-2006 Buick Rainier2002-2006 Chevrolet TrailBlazer, TrailBlazer EXT2002-2006 GMC Envoy, Envoy XL2004-2005 GMC Envoy XUV2005-2006 GMC Envoy Denali, Envoy XL Denali2002-2004 Oldsmobile Bravada2005-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.
Make sure you check those wires as described in the TSB above. Also check all the fuses.