Quick question: When you say the headlights blink, do they do so on a regular pattern, in other words, off and on with regular spacing. Or do they just flicker off and on randomly.
A flicker, is a loose wire or connection, and can often be found by wiggling the wires until you make the lights blink.
A regular pattern is the circuit breaker in the headlight circuit going on and off. That can be caused by a bad breaker, a partial short, or the previous owner may have installed aftermarket headlights that draw too much current for the system.
The two different symptoms require different trouble shooting methods.
Also, I would ignore the O2 sensor code right now. It sounds like a misfire of some kind which would cause the code on a good sensor. Check the wiring around the distributor for any signs of corrosion or loose connections.