A circuit that will do what is wanted, or as much as what is wanted as has been revealed, is shown below.
This circuit is much simpler than it sounded like it was going to need to be, due to the revelation that the USB power feed could easily accomodate a Schottky "blocking dioe" and still meet the Vout requirement. If this diode had had too high a voltage drop to be acceptable then a circuit withtime delays and current flow direction detection would hav ebeen needed. It can be surprising how much difference a little more information can make to the solution of a problem.
Battery feed at top. USB power feed at bottom.
USB power is fed to load via Schottky diode D1. Power may be fed via Ja and the LDO regulator or via JB as desired.
If feed via JB is used the LDO must survive with external voltage on its output when it has no input. If necessary (depends on LDO) adding another Schottky diode across Ja "pointing upwards" would apply the same voltage across either side of the LDO and minimise quiescent current (in most cases) when USB power is in use.If absolutely necessary another FET could be used to block USB feed from LDO but should not be needed. LDO could be put above Q3 BUT then battery supplies LDO quiescent current at all times = poor.
When USB voltage is absent Q3 = P Channel MOSFET is turned on by R4, feeding battery voltage to LDO and thence to Vout.
When USB voltage is present Q1 is trurned on by R2/R3 and this turns on Q2 (usually held off by R1) which clamps Q3 gate high turning it off, thus disabling battery feed. USB power feeds via D1 either via Ja and LDo or Jb as above.
Battery current when USB connected:
Changed R1, R4, R5 to nominal 1 megohm each to reduce battery load when USB in use. A small MOSFET for Q2 and/or some more thinking will reduce required standby current.
USB on, Q1 on, About 5 uA via R5 to turn Q2 on. About 5 uA via R4 to turn Q3 off. R4 can probably be 10M if slow response OK. ( At R4 = 10 megohm if gate capcitance on Q3 is say 10 nF then time constant for turn on = RC = 1E7 x 10E-9 =~ 0.1 second. Depending on =FET gate threshold it MAY take a few 10ths of a secind for battery to turn on when USB is unplugged. This could dropout powered cct unless a large enough output cap was provided. At R4 = 1m the time constant is about 10 milliseconds and a "usual" sort of cap on output rail would suffice.
Can be "tuned". Q1 on removes voltage from R1. 10 uA quiescent when USB is on =~ 90 mAh/year. This is about 3% of battery pack capacity. Small but annoying.
Q1, Q2 = almost any jellybean bipolar. Q3 = P Channel MOSFET. Vthreshold << Vbattery. D1 = Schottky eg 1N5817. LDO to suit.
Roll your own LDO with MOSFET and eg TLV431 can have about 100 uA quiescent when running and essentially zero dropout voltage. Can be much lower with lower Iq ref diode.
BUT
When you can get eg Microchip's VERY nice TC2104 LDO for under 50 cents in 1's, making your own makes less sense.
Added 9/2015
Kar asked
... why are the BJTs needed?
Why not just have a MOSFET and a diode, and that's it?
@Kar Good question.
The MOSFET solution is a good one but it is slightly more design-demanding than may be apparent, whereas the bipolar solution uses a few more components but is easier to ensure operation ioj all conditions.
Tpo use the MOSFET as shown the FET's Vgsth must be chosen to suit.
Battery max voltage (assuming his AA cells are Alkaline) is 1.65V (new cells) x 4 = 6.6V.
In a few cases even maybe 1.655V so say 6.8V for 4.
USB is say 5.3V max when on and 0V when off after any capacitors discharge.
But critical here is not USB Vmax but USB_on_min
USB_on_min = say 4.8V.
Under that condition FET must be off, so
FET Vgs = (6.8-4.8) =~~~~ 2V worst case.
The FET MUST NOT turn on at Vgs = 2V.
Battery min is say 4V and USB low falls to 0V "after a while" so FET must turn on at Vgs = 4V. That puts the FET Vgs_off_max and Vgs_on_min in a fairly narrow 2 to 4V range.
That's certainly doable by correct choice of FET - but datasheet must be chacked to ensure that worst case spread lies in the desired range.
The designer needs to be aware that design is needed!
In the bipolar case the USB Von_min is very easily accommodated by Q1 and if desired full turnoff can occur when V_USB is say 2V so changeover to battery is better defined.
So overall, the bipolar addition adds 2 x Q and 4 x R (small but non trivial) for the sake of better flexibility and designability.
BUT the MOSFET only solution is a good one as long as the complexity that goes along with the simplicity is properly understood.
When charging lithium batteries in series, you need what's known as a balance charger to keep the cells at similar voltage. One way that some chargers do this is by stopping the charge of both when one is full, discharging the full one until they are even, and then charge them both up again. There are fully featured chargers meant for the remote control hobby, but they require setting the charge options on the screen before every charge. I cannot seem to find any "plug and play" balance charger boards similar to the TP4056. I am fairly sure that ICs exist that will handle the buck/boost power supply and the balancing, but I can't seem to find one and you would need to manufacture your own circuit board, and the chip is almost certainly surface mount.
That being said, there are a few workarounds. One is to have the batteries in series for operation and parallel for charging, and use either one or two single cell chargers. This can be accomplished through a 3PDT switch, and a good explanation is here. Note that you don't need to use the same charger, your TP4056 should be able to be substituted.
A simpler and more elegant way to do it would be to use a boost mode power supply, and don't put the cells in series. You can attach multiple of your current cells in parallel, so that if you have two cells and are drawing 5W, it would be 2.5W per cell or ~0.67A. There are many chargers that are designed for this application, handling both the CC-CV charging and the boost regulator for the output, such as the Lipo Rider Pro from Seeed Studio which will do 1A output. This is what I would recommend.
Alternatively, you can buy more powerful batteries that will put out more than 1A instead of putting multiple in parallel.
Or if you want to take all the fun out of this project and just buy something that sort of works, there are USB battery banks available from China that will take care of all the charging and discharging of 18650 LiPo batteries. I have seen banks that will take from one to six 18650 cells in parallel, and some of the larger ones can do as much as 3A output. Here are a few examples, and a video review. Their build qualities and user interfaces look pretty bad, but apparently they work.
Best Answer
Resistors will not be the best option, you need to know the source current of the device and there will be large voltage swings if the device changes it's current. Resistors may also not be possible if the device draws large amounts of current.
Three alkaline batteries is lower than 4.5V (could be as low as 3.6V when their dead). Since the device running from 3 alkaline batteries should be able to accept 4.5V, a voltage regulator like the might be a good way to ensure that the device is getting the appropriate voltage, however you might need to select one with a lower dropout than 0.5V which might be hard if your device needs more than 100mA.
Another option would be to find out if the device already has a linear regulator or switching regulator on the input. If it does, then you might be able to run 5V straight into the device.