my English is pretty advanced and I have a great accent but I'm really bad at writing formal emails or essays , I would really appreciate it if you could help me on that or give me some tips.
Shirin, as you probably already know, language learning is not an isolated skill; you do not just learn a language by brute-force memorizing vocabulary and grammar rules from a textbook. Instead, learning a language always takes place within a relevant context - with people that you enjoy spending time with, with topics that you are interested in, with food that you enjoy eating, with songs that you enjoy listening to.
The best way to work on your writing is: (1) find a subject or topic that you really care about (such as philosophy, history, art, technology), and then (2) read a lot on that subject and then finally (3) give your opinion (agree / disagree / etc) on what you just read. That way, you are learning from how other native writers in that language use grammar, vocabulary, and what their styles are. You can take inspiration from that and kind of imitate some elements of their style. And you also have some context (from what you read) to write an essay about.
Then (4) ask native speakers of that language to revise or edit your essay. At this point, you probably need someone with a high level of education, because your English is probably more advanced than the average American.
If you read the autobiography of BETRAND RUSSEL, your writting skill will improve. It contains lots of real time letters.
Vocabulary also will improve.