Definitely sounds like the crank position sensor has either gotten dirty or has started to go.
The CKP sensor senses the gaps in an interupter ring as ON-OFF pulses. On these S2 engines, the ring is a two stage ring. The outer ring is an 18 pulse per revolution and the inner ring is a 3 pulse per revolution. The reference to P0336 is the code for the Crank Position Sensor and specifically the 18x reference signal from the CKP sensor.
Since it is very intermittent when it happens, it could just be debri in the way of the sensor. The problem is that to get in there and clean it, you have to remove the harmonic balancer.
shows me that the CKP sensor is P/N 10456161 and standard replacement at a dealership (book time) should be around 2.1 hours. GMPartsDirect.com
confirms the P/N and shows the replacement sensor to be $24.32 + shipping.
If you have the tools (a harmonic balancer puller is a must and can be rented from most auto parts stores) and the time, it would be quite cheap to replace the sensor yourself. If you are bothering to pull the balancer, for ~$30 you could have a new sensor put in and forget about it.
Good luck and let us know how it works out.