E. Cobham Brewer 18101897. Dictionary of Phrase and Fable. 1898.
Don Quixote de la Mancha, riding through the plains of Montiel, approached thirty or forty windmills, which he declared to Sancho Panza were giants, two leagues in length or more. Striking his spurs into Rosinante, with his lance in rest, he drove at one of the monsters dreadful as Typhus. The lance lodged in the sail, and the latter, striking both man and beast, lifted them into the air, shivering the lance to pieces. When the valiant knight and his steed fell to the ground they were both much injured, and Don Quixote declared that the enchanter Freston, who carried off his library with all the books therein, had changed the giants into windmills out of malice. (Cervantes: Don Quixote, bk. i. ch. viii.)
To fight with windmills. To combat chimeras. The French have the same proverb, Se battre contre des moulins à vent. The allusion is, of course, to the adventure of Don Quixote referred to above.
To have windmills in your head. Fancies, chimeras. Similar to bees in your bonnet (q.v.). Sancho Panza says
Did I not tell your worship they were wind-mills? and who could have thought otherwise, except such as had windmills in their head?Cervantes: Don Quixote, bk. i. ch. viii.