early 14c., "one who holds an official post, one entrusted with a responsibility or share of the management of some undertaking" (originally a high office), from Old French oficier "officer, official" (early 14c., Modern French officier), from Medieval Latin officiarius "an officer," from Latin officium "a service, a duty" (see office).
In Middle English also "a servant, a retainer of a great household; an official at court" (late 14c.). From late 14c. as "a military retainer," but the modern military sense of "one who holds a commission in the army or navy" is from 1560s. Applied to petty officials of justice from 16c.; U.S. use in reference to policemen is from 1880s.
The phrase officer and a gentleman in reference to one having the qualities of both is by 1762 and was standard language in British court-martial indictments ("behaviour infamous and scandalous such as is unbecoming the character of an officer and a gentleman").
The words 'officer and gentleman,' though in general to be understood as one single and indivisible term, appear not to be so used here. The misbehaviour, entailing on it the penalty declared by this article, must be such, as I understand it, as to implicate, in the first place, the officer; that is, it must arise in some sort out of his office; and affect incidentally only, the character of the gentleman. It must be such a misconduct, as must necessarily dissever what should ever be indivisible, the consideration of the officer from the gentleman. It must be of that decisively low, humiliating, and debasing kind, as to lay prostrate the honour of the gentleman, in the degradation of the officer. [Capt. Hough and George Long, "The Practice of Courts-Martial," London, 1825]