What is the code?
Do you have either Tunerpro or ECMSpy?
Your symptoms could have a large number of causes. Knowing the code will help. My best guess would be a poor electrical connection in any number of areas, including the connector(s) at the ECM, or at one of the sensors. Could also be a faulty sensor or voltage regulator.