Can outlook365 for mac be installed and connect to an email server via a script?
Absolutely. Mac administrators script this all the time. Microsoft has employees that are on the mac admin slack and publicly provides training documentation on the preferences that the Outlook app and office suite have for easing on boarding.

https://docs.google.com/spreadsheets/d/1ESX5td0y0OP3jdzZ-C2SItm-TUi-iA_bcHCBvaoCumw/edit#gid=0
https://macadmins.software

If that’s too dry or verbose, you can start with a much nicer package of 25 pages of wiki goodness on setting up Outlook.

https://github.com/talkingmoose/Outlook-Exchange-Setup-5/wiki

I would start small and then iterate, solve little problems first and then get more complete over time as you can save time based on how many machines you are setting up. Also remember, at some point, no automation will save you time if you spend more time learning than just setting up a handful of Macs but conversely, no amount of time will be wasted if you can never set things up manually. You’ll always come out ahead in that case.
This is a well established script and you might be able to adopt someone else’s solution with just a few hours or reading or even less if you already script on macOS.