Sedatives and hypnotics made from Chinese herbal medicine show great market prospects for minor side effects and zero potential addiction. In this study, the extraction conditions of Cordyceps militaris polysaccharide (CMP) and flavonoids (CMF) were, respectively, optimized by orthogonal experiments as follows: 30:1 ratio of water to plant material, three rounds of extraction at 90 °C and 3 h for each extraction; 40:1 ratio of 70% ethanol to plant material, reflux extraction at 90 °C for 4 h. Then, 200, 100 and 50 mg/kg of CMP and CMF were given intragastrically to mice for 30 days. The locomotor activity times of the mice were recorded on the 14th and 30th days. The effects of CMP and CMF on the sleep induced by pentobarbital sodium were observed on the 30th day. 5-Hydroxytryptamine (5-HT), acetylcholine (ACh), glutamate (Glu) and γ-aminobutyric acid (GABA) levels in the mouse brains were determined by enzyme-linked immunosorbent assay on the 30th day. The results showed that different doses of CMP and CMF could reduce the number of locomotor activities in mice and lower the Glu level (p < 0.05 in the 50 mg/kg CMP group and p < 0.01 in the other groups), elevate the 5-HT level and reduce the ACh level (p < 0.01 only in the 200 mg/kg CMP and CMF groups) in the mouse brains. Therefore, the elevated 5-HT levels and decreased ACh and Glu levels in the brains may be the main mechanisms through which CMP and CMF exert their sedative and hypnotic effects.