Four US military officers who were detained in Libya have been released after being held in custody for several hours, American officials have confirmed.