How to automatically disconnect from battery when USB +5v is present
There are IC's designed specifically for this, and in small packages too. One example is TPS2113A from TI. The TPS2121 is another option if you need higher current. Other suppliers like Maxim make devices as well. Search for "power mux IC".