I am confused when it is ok to use deadly force away from home.
In one phrase, essentially, justified use of lethal force requires that the innocent be in immediate and otherwise unavoidable danger of death or grave bodily harm.
Basically, as others have said: if you're legitimately threatened, what're you gonna do ... pause to whip out the legal text until you can find the applicable state code that covers what you're about to do? Absolutely not. If you're legitimately threatened, absolutely defend. If you're at legitimate risk of losing your life, defend even up to the point of using deadly force to defend it.
Keep in mind the "Reasonable Man Standard," in which you are given legal authority to decide what's reasonable right then and there, but ultimately your peers (in a jury) get the authority to determine what was reasonable, in hindsight. Ensure you know how this applies to your state's laws related to self-defense.
Read this:
Justifiable self defense.
Acquire a copy of Massad Ayoob's book,
In The Gravest Extreme. Read it a second time.
Consider taking one or two weekend seminars on self-defense and the justifiable, legal use of force in your state. Each state's laws are different. Some states restrict you nearly to the point of inability to defend yourself without stepping in one of a tangle of legal potholes seemingly placed there to trip you up. In many states, "Castle" laws seek to protect the absolute right of a person to defend against violent crime. You need to learn to know and love your state's laws on the use of force, the use of lethal force, the concealed carry and open carry laws ... until you can feel them in your bones. Find a good attorney who is competent in the successful defense of folks involved in self-defense shootings against criminals.