Opioid-based drugs are frequently used for pain management in both males and females despite the known risk of prefrontal cortex dysfunction and cognitive impairments. Although poorly understood, loss of cognitive control following chronic drug use has been linked to decreased activation of frontal cortex regions. Here, we show that self-administration of the potent opioid, remifentanil, causes a long-lasting hypoactive basal state evidenced by a decrease in ex vivo excitability that is paralleled by an increase in firing capacity of layer 5/6 pyramidal neurons in the prelimbic, but not infralimbic region of the medial prefrontal cortex. This phenomenon was observed in females after as few as 5 days and up to 25-30 days of self-administration. In contrast, pyramidal neurons in males showed increased excitability following 10-16 days of self-administration, with hypoactive states arising only following 25-30 days of self-administration. The emergence of a hypoactive, but not hyperactive basal state following remifentanil self-administration aligned with deficits in cognitive flexibility as assessed using an operant-based attentional set-shifting task. In females, the hypoactive basal state is driven by a reduction in excitatory synaptic transmission mediated by AMPA-type glutamate receptors. Alternatively, hyper- and hypoactive states in males align selectively with decreased and increased GABA signaling, respectively. Chemogenetic compensation for this hypoactive state prior to testing restored cognitive flexibility, basal hypoactive state, and remifentanil-induced plasticity. These data define cellular and synaptic mechanisms by which opioids impair prefrontal function and cognitive control; indicating that interventions aimed at targeting opioid-induced adaptations should be tailored based on biological sex.