Two American mariners and their canine companions have been rescued after drifting off course and spending months stranded in the Pacific Ocean, the US Navy says.