寺 originally meant a government office, then became the word for Buddhist temples. 庙 is for folk religion shrines. Together they cover temples in general.
Strictly speaking, 寺 is for Buddhist temples and 庙 is for Taoist/folk religion temples, but in everyday Chinese 寺庙 is used as a general word for any temple.