Are you syncing from on-prem to Exchange Online with AADConnect?
If so, then what you really want to do is create a remote shared mailbox with your existing code on-prem and not directly in 365.
For connecting to Exchange Online, use the App-based auth:
https://learn.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps