I had five capital ships and a number of frigates in my fleet, plus a repair cruiser
That fleet isn't well balanced. You should have fewer capital ships, and far more repair cruisers. As a rule of thumb, your fleet supply research should be an equal or higher level than your capital ship crew research. This means that for a fleet with five capital ships, you should have well over a hundred frigates. If you have fewer frigates than this, you're going too heavily on capital ships.
As for the Hoshiko (repair cruisers) you should have over a dozen of them. The sheer longevity these things can give your fleet is absolutely phenomenal, but if they run out of antimatter then they turn into big bricks that don't do very much. You need a lot of them to get efficiency.
I was building up defenses at some of the outlying bases.
What kind of defenses were you building? Generally the best form of defenses are cheap repair bays. These stack with repair cruisers (enabling you to potentially heal for over 60 hull points per second) and are really cost-efficient. If you want to build a more powerful defense and intend to spend more than 3000 credits, you may as well build a starbase. Now 3000 credits may seem like a lot, but a few tactical planet upgrades, a couple of hangers, and a smattering of turrets later and you may have spent far more than that. Turrets in particular are deceptively expensive due to their high metal and crystal cost.
It's a good idea to surround any starbase you build with repair bays. Usually this defense requires no tactical upgrades from the planet, which actually ends up costing you a lot less while getting you a better defense.
Then the inevitable happened: an asteroid was attacked and I lost it after a long battle, all the while churning out frigates to defend it, and while I was retreating
Again, without actually seeing the match I can't tell you what went wrong, but I'll try to give generic advice to help. I suspect you had too little in the form or repair, and probably got caught by surprise, which is always a recipe for disaster. Repair platforms are your top priority as a defensive structure, and you need to constantly be aware of the enemy fleet's position so your own fleet is ready to defend. The AI is particularly slow with fleet-wide manoeuvers and deployment, so if you're paying attention it's very rare that the AI will actually get the drop on you. My guess is that you got comfortable in a defensive position and stopped scouting, and weren't aware of the AI repositioning its fleet to attack a different front.
and while I was retreating, my other planet revolted and another asteroid was attacked!
Revolts don't happen overnight; they take about 10 minutes to occur on average, and give plenty of warning. When a phase lane changes colour, it's because someone is broadcasting propaganda. You can interfere with this by stationing defensive capital ships, but that's like bailing water in a sinking ship, a very temporary solution (plus a waste of expensive capital ships). You can usually cancel it out with broadcast centers of your own; usually one defensive center for every two "attacking" centers is enough. As well, friendly propaganda will give you a small economic boost.
Their fleet was about five times as big as mine. So while they were destroying my asteroid, they still had a gigantic fleet that was able to defend one of their asteroids.
What probably happened is that during the big battle, they lost many units. The fleet you encountered was the new replacements built in the meantime. It sounds like you still have ground to cover in terms of building a competitive empire and economy.
If I try to take one of the enemy's less-defended planet/asteroids, by the time I can even destroy one structure, his fleet shows up in overwhelming force to defend and I must retreat.
Well, the obvious problem here is that your fleet is smaller, and you still need to work on maintaining a competitive fleet size and economy.
I don't see the benefit of all my research into advanced weaponry when it takes my whole fleet concentrating on one enemy ship so long to destroy it
People have done the break-even analysis on those upgrades, typically you need dozens and dozens of units to make them cost-effective. In most situations, you're better off maintaining a large fleet. Now, hull and armor upgrades are a better deal, and different upgrades have different degrees of utility (Vasari phase missiles are to die for). In general, though, fleet first, ugprades later.
I can't believe that the enemy is able to be as technologically advanced as me AND have enough resources to produce enormous fleets!
He probably wasn't as technologically advanced as you, but if you have +20% damage, he only needs 20% more units than you to get the same damage output, but he has more hit points to back it up. In general, those technology upgrades are slight advantages that tweak battles in your favour. Putting all your money into technology is a bad idea, since you'll just be swamped by pure numbers of stock frigates.
Also can someone get this guy a replay of a comp stomp? I don't have my gaming computer right now and can't produce one for him. It'd be useful if he could see how an experienced player plans his economy and fleet.