From Article II, Section 2 of the US Constitution:
[The President] by and with the Advice and Consent of the Senate, shall appoint Ambassadors, other public Ministers and Consuls, Judges of the supreme Court, and all other Officers of the United States, whose Appointments are not herein otherwise provided for, and which shall be established by Law: but the Congress may by Law vest the Appointment of such inferior Officers, as they think proper, in the President alone, in the Courts of Law, or in the Heads of Departments.
Under this clause, all federal officers, military or civilian, must be appointed by the President with the advices and consent of the Senate, unless (and it’s a big unless) the law establishing the position provides for Presidential appointment without Senate confirmation or appointment by lesser authority.
Under the law governing the armed forces, original appointments as military officers in the grade of Army/Air Force/Marines Captain or Navy Lieutenant, or below, may be made by the President alone, but Majors/Lieutenant Commanders and above require Senate confirmation. 10 USC 531. Similarly, promotion to the grade of Army/Air Force/Marines Captain or Navy Lieutenant may be made by the President alone, while promotion to Major/Lieutenant Commander and above require Senate confirmation. 10 USC 624(c). Normally, the Senate gets a promotion list of, say, Navy Commanders to be promoted to Captain, and routinely confirms the list, though I have heard of the Senate holding up lower officer promotions when it is in a spat with the President over defense policy.
In addition to Senate confirmation to a military officer rank, certain positions (like the 3 and 4 star positions noted above under 10 USC 601) require that the officer occupying the position be specifically appointed and confirmed in the position. Otherwise, I believe the President, as commander in chief, and his Defense Department subordinates have pretty free reign to appoint officers of appropriate rank to positions as necessary for military needs.