I should probably qualify a few things first: I'm not a "skilled" player, only intermediate (possibly higher end of intermediate, but I won't make any substantial claims as such) I've played about 20-30 games of vanilla online and only 4-6 of entrenchment. Obviously most of my experience is with vanilla.
Now the basic answer to your question is: it depends on the game and situation.
Vanilla is much different than entrenchment, as is team game versus 1v1.
In a 1v, if you're holed up in your HW trying to stave off his attacks and he vastly outnumbers you, odds are it's over, just give up (unless you want to practice seeing how long you can hold up, never a bad option). In a 1v1, offense IS your best defense, and you want to keep the pressure on without suffering too many losses.
In a team game, you may be losing at the moment, but if your teammates are winning then all you have to do is hold out as long as possible. The very fact that you're not out of the game and you're occupying your opponents attention means you are keeping them from getting back up reinforcements. If you are holed up in your hw and your mates think they can win, hold off ALAP.
Obviously though, you don't want to holed up in your HW as a rule. By fringe, I mean the outermost planets of your territory, particularly an asteroid. When I say fall back and let them take the fringe planets, I mean if they vastly outnumber you and you KNOW that you can't take the fleet yet. Losing an asteroid isn't THAT big of a deal (though you do want to avoid losing if possible), but a planet you probably do want to keep around IF POSSIBLE.
The colony you have closest to the enemy you always want a lot of repair bays (I usually have three, but more isn't necessarily a bad thing either) so you can fall back to repair or hold the line. You can then reinforce those with turrets, and PJI to force some nasty casualties. In nilla, I pretty much never build hangars as flak will render them much more costly than effective. I don't know enough about entrench to say about them though, as the added abilities might make them much more formidable. Now, to protect the defenses from SC you can keep a LOT of flak on hold position near them and put fighters on Local area around the repair and turrets. Do it right and your opponent will either be forced to confront you at the defenses, or try to skip past them to next planet (which is where the PJI comes in handy).
Now, there are cases where both of you are ransacking each other's territory, and here it simply becomes a judgment call on how long you want to play chicken. If you think your opponent will cave and try to come back to defend himself, by all means ransack his shit. Likewise, if you know you can take him out quicker than he can you harm you, then stay (especially if you are ready to colonize what you just ransacked). Otherwise, it may be a smarter idea to fall back and defend.
Hope this helps. It's best I can do at my current experience level.