1879, from Latin optimum, neuter singular of optimus "best, very good" (used as a superlative of bonus "good"), perhaps (Watkins) related to ops "power, resources" (in which case the evolution is from "richest" to "the most esteemed," thus from PIE root *op- "to work, produce in abundance"); or perhaps it is related to ob "in front of" (de Vaan), with superlative suffix *-tumos.
In English the word was used originally in biology, in reference to "conditions most favorable" (for growth, metabolic processes, etc.). As an adjective, "best or most favorable," from 1885.