This sounds like a classic crankshaft angle sensor that is going out. Here is a guide that will give you an idea on what you are in for when doing the job on your car.
Repair Safety Notice: This information is for general instructional purposes only. Vehicle repair can be dangerous. Verify all information, follow manufacturer service procedures, use proper tools and safety equipment, and consult a qualified repair shop when needed.