Android - Block all sounds going out through speaker when headphone connected
Currently you can't disable notifications via speakers while still having them via headphones. There's an open issue for that.
You also can use Llama or Tasker to switch profiles when you plug your headphones.
I saw you had another question about Cyanogenmod, and thought I'd point out that it has the option "Always play on speaker" for notifications, ringtones and alarms (in Settings -> CyanogenMod Settings -> Sound
). So as soon as it's stable (if it's developed further) it can solve most of your problems.