I think I found a fix to this problem.
Please follow these steps:
1. Make a backup of Apple Mail messages if you store anything locally (like storing something On My Mac, downloading via POP3 etc).
2. Go to System Preferences > Internet Accounts.
3. Delete all Exchange accounts.
4. Delete ~/Library/Mail and ~/Library/Containers/com.apple.mail folders (this will reset Apple Mail and its preferences).
5. Restart the Mac and uncheck "Reopen windows when logging back in" to make sure Apple Mail won't start after rebooting.
6. Go to Internet Accounts, click on +, select Exchange, enter your name and email address.
7. Click on Configure Manually and enter your password.
8. Uncheck everything (like Contacts, Notes, Calendar etc) and leave only Mail checked. You will be able to add it later (see below).
9. Start Apple Mail and go to Preferences > Accounts.
10. Select your Exchange account and click on Server Settings tab.
11. Uncheck "Automatically manage connection settings".
12. Make sure both Internal and External URLs are set to
https://outlook.office365.com/EWS/Exchange.asmx.
13. Close Preferences and restart Apple Mail.
14. If you need Contacts and Calendars, go to System Preferences > Internet Accounts, select your Exchange account and enable the services you need to sync.
Thats it. I was waiting for 2 days and it's been working fine so far, no CPU spikes when no connection, accountsd and Mail processes are quiet.
Let me know if it helps or if you have any other questions regarding this.