Try switching all of your ship capture projects to be ship specific, and take the ships that are harrasing your planets.
Not only will the anger due to enemy presence go down, but you'll also get the happiness due to "your" military presence. You can then use your captured ships to kill off the rest of the enemy raiders.
When things stabilize, (or before things got ugly), I'd reccommend a turns worth of mines in orbit of every planet. They'll pick off the AI raiders very nicely.
As you have noticed, troops are another thing that you must build
before you need them.
20 Police Troops per planet can keep your economy running smoothly. (Design a small troop with a cockpit and nothing else. You can build 'em really quick)