It can be written as two words ( buona notte ) or one ( buonanotte ). The single-word version is mandatory when used as a noun, such as in the phrase dare la buonanotte (to say goodnight).

When writing in Italian at the end of a letter/email "Good ... - italki

It is exclusively a farewell used late at night when someone is going to sleep or leaving for the day.