Although context is important in deciding whether to use formal or informal writing, the message itself can be written in any style based on your writing choices. Thats why its crucial to learn the difference so you dont write too formally or too informally in the wrong situation.
If you are unsure of whether to use informal or formal writing, its generally the rule of thumb to start out writing formally. Then, when you make the connection and you see how the other side responds, you can ease up on the formality.
Formal English is used in professional, academic, or official settings. It is characterized by its adherence to grammatical rules, precise vocabulary, and structured tone.

Furthermore, visual representations like the one above help us fully grasp the concept of It Is Used In Formal Writing.
It is the form of English that follows the formal rules of the language. Nonstandard English uses regional or social language variations. Nonstandard English should only be used when there is a purpose for it in writing. For example, it can be used in a narrative to describe a person...
Formal English: We use it when writing essays for school, cover letters to apply for jobs, or emails and letters at work. Informal English: We use it with friends, children, and relatives. The following list will help you to recognize the informal and formal ways of saying the same thing.

In summary, it often involves complex sentences, sophisticated words, and writing in third person. Using passive voice is acceptable, but colloquial language is definitely not. Note: if you're using a formal tone, make sure you write clearly.
If you write less formal information, such as marketing information, you can use em dashes for emphasis. Developing Quality Technical Information: A Handbook for Writers and Editors.As far as if an em dash can be used in formal writing, it certainly can if it is allowed (see above).