Best way to switch between multiple power rails based on whether they're present or not
So there is a lot here to figure out. Assuming everything on your board will run on one regulated voltage, there are several options. 

Simple diodes can do a lot of what you're asking. Coupled with a linear regulator, and accounting for some loss, this could be the easiest solution. Your battery voltage could be a problem, as if it is lower than 5V, the priority wouldn't be correct. This EE stack exchange answer and this one provide some diagrams of simple 2 source solutions, but more sources can be added in the same way.

More complicated solutions are possible using resistor and diode networks to switch a series of mosfets. Another EE stack exchange answer provides some examples.

There are also IC's for this (As for most things). Look for "PowerPath" or "ORing controller" ICs. A few dollars will buy you an incredibly capable product like LTC4090-3, which will handle 12V in, USB, and battery, while controlling a buck circuit and charging your battery for you as well. It will need another regulator, and will output a max of 5V, but it produces exactly the priority switching control you require.

This overview by Analog would be good for some IC based ideas, and has several circuit topologies as well as part selection tables.

Another link with more information about other manufacturers parts.