As a native speaker I'm not aware of detailed rules on the matter. There are a lot of implicit rules unknown to most natives which non-native speakers need to learn, so I searched online, but in this case it seems there are no special rules.
If you understand academic Italian you can read this:
It's a detailed explanation by Accademia della Crusca, the most authoritative institution for Italian language. Briefly, they say that choice of preposition depends on the word it precedes, the verb it follows, and the nuance you want to convey.
Their style is a bit difficult, but if you can understand their writing I suggest you always refer to their website when in doubt. You can also directly ask questions to academy linguists.
Here are some general rules:
Different words and phrases need different prepositions: you can say «in mattinata» and «in serata», meaning «in the morning» and «in the evening», but you can't say «in mattina» nor «in sera». Conversely, you can say «la mattina» but you can't say «la mattinata». Also, you can't use a/alla with notte: you can say «la notte» and «di notte», but you can't say «a notte». A good dictionary will help you here.
Hours need a/alla/alle: same as in English; you say «viene a mezzogiorno», «viene alle tre», and you don't say «viene in mezzogiorno» just as you don't say «he's coming in three o'clock».
Months preceded by di are not temporal expressions (complementi di tempo): «a maggio» and «in maggio» both mean «in May»; «di maggio» means «of May».
Adverbs of time don't need a preposition when used in temporal expressions: ieri, domani, dopo and similar adverbs form by themselves temporal expressions.
Locutions make special usage of prepositions and must be memorized: examples are «di prima mattina», which only allows di, or «a notte fonda» and «a tarda notte», which make use of a before notte.
As regards the definitive article, I feel it as a bit colloquial. I would not write «la mattina» or «la sera». It's fine when joined with the preposition (al/alla/del/della), but only with words allowing it (e.g. hours). «Bevo caffè alla mattina» sounds a bit old-fashioned where I live (Rome), though I think it's common in other regions. Better is to use «alla mattina» and «alla sera» in the beginning of a sentence, meaning «when the morning comes» and «when the evening comes».