Improvisation
there are no bad notes. All that matters is where you came from, where you go next, and how long you play it. If you play a note that sounds sour, treat it as a passing note and move or down 1 fret. You will never be more than 1 fret away from a note that is in the scale.
substituting the VI for the vi is common. A bVII chord is very common. Using both the IV and the iv chords is common (lots of old Beatles and Beach Boys tunes use that sound).
if you know the key, sticking to scales related to the I or V is likely to get you in key.
If you hear an atypical chord change within the key, and you didn't anticipate the chord beforehand, chances are you will be a half-step above or below what the tonic was before