Most physicians recommend that you do not take sleeping pills if you have obstructive sleep apnea (OSA). However, as is usually the case with medical advice, the answer gets a bit more complicated.
Benzodiazepines, a commonly prescribed class of sleeping pills and anxiety reducing agents, have been shown to decrease breathing in some but not all subjects with OSA. Because it is impossible to predict who will respond badly to these drugs they are not recommended for patients with untreated OSA. These drugs include Xanax®, Klonopin®, Valium®, and Restoril® among others. A newer class of non-benzodiazepine sleeping pills such as eszopiclone (Lunesta®) or zolpidem (Ambien®) appears to be safe to use by patients with OSA, especially if they are using continuous positive airway pressure. In fact Lunesta® was found to improve patient's use of CPAP over a period of 24 weeks when given for the first two weeks of treatment, while they were getting used to the device. It is possible that a non-benzodiazepine drug would help with adaption to other mechanical means of treating OSA, such as oral appliance therapy (OAT) or expiratory positive airway pressure (EPAP) treatment, but this has not been tested.
Certain drugs are certainly to be avoided by patients with untreated OSA. These include opioid pain such as morphine and barbiturates which can severely interfere with breathing.
Over-the-counter sleeping aids containing antihistamines are probably safe, but have not been well studied in patients with untreated OSA.
That leaves alcohol, which is widely used and is a known to depress breathing. Patients with untreated OSA should not use for four to five hours before bedtime. However if you have uncomplicated OSA moderate amounts of alcohol has been shown to not diminish the effectiveness of CPAP.
If you have OSA the bottom line is you should use sleeping pills and sleeping aids with caution.