Q:

Can you use Total Defense out of combat? 

Can you add the dodge bonus from Total Defense when you aren't in combat but anticipating an attack
For instance I think there's goblins on the other side of the door.  We snuck past them when they were sleeping, and now they sent a few through the door.  We are not in combat yet.  We are expecting goblin arrow attack.  I use Total Defense before I open the door.  The door opens, goblins shoot at me.  Do I get the total defense bonus? 

A:

I disagree with the premise

We are not in combat yet. 

Both parties are hostile, aware of each other, and making combat-related actions — combat has already begun.  The only reason attacks have not been exchanged is that both sides enjoy total cover due to the presence of the closed door. 

A:

Yes:

Total Defense
You can defend yourself as a standard action.  You get a +4 dodge bonus
  to your AC for 1 round.  Your AC improves at the start of this action. 
  You can’t combine total defense with fighting defensively or with the
  benefit of the Combat Expertise feat (since both of those require you
  to declare an attack or full attack).  You can’t make attacks of
  opportunity while using total defense. 

(Source: SRD, Actions in Combat)
Given that it's a standard action, the real question is, is opening a door a move or a standard action? 

Manipulate an Item
In most cases, moving or manipulating an item is a move action. 
This includes retrieving or putting away a stored item, picking up an
  item, moving a heavy object, and opening a door.  Examples of this kind
  of action, along with whether they incur an attack of opportunity, are
  given in Table: Move Actions. 

(Ibid.) 
This specifically says that opening a door is a type of item manipulation, and that is a move action.  Given you typically get one standard action and one movement action, I'd say yes. 

A:

Here's how I think about this: it's very similar to the old question about "can you ready an action outside of combat?".   Opinions about this seem to be mixed, but my answer to that question is: that's what the surprise round represents.   
If you know there are goblins behind the door, and the goblins don't know you're coming, then you and all your friends could ready an action to attack the goblins.   But having everyone go around the table and say "I ready an action" is tiresome, so we just declare a surprise round and give everyone a standard action.   
On the other hand, if the goblins do know you're coming, then presumably the goblins have a readied action as well.   When lots of creatures have readied actions which all fire at once, we have to roll initiative to see which ones fire first -- so at that point we might as well just go into the initiative sequence and let everyone take their actions in initiative order. 

Here's how your goblin example should work.   If you know there are goblins behind the door, and the goblins don't know you are there, then you get a surprise round at the start of combat.   During your surprise round you can declare total defense.   Then, (if the goblins get a higher initiative roll than you), when the goblins shoot at you, you get your dodge bonus. 
If you know there are goblins behind the door, and the goblins do know you are there, then you don't get your surprise round, and you don't get to start with total defense. 
You could imagine saying "I declare total defense and then I open the door" -- but if combat starts and the goblins beat your initiative, then they have caught you flat-footed, which means you lose your Dexterity bonus to AC and also your dodge bonuses. 
(Elsewhere you've asked: "what if I have uncanny dodge, which allows me to keep my dexterity and dodge bonus when flat-footed?".   It's messy, but I think I'd have to concede that this works the way you want it to.) 

Having said all that, I do think there are situations where you can declare total defense outside of combat.   For example, if you know that a swinging blade trap is going to attack you when you step on a given pressure plate, you could say "I declare total defense against the swinging blade trap" and get your +4 AC.