The message “Unable to connect to server (null)” does not, by itself, identify the cause. Begin by confirming that you can sign in to your Yahoo Mail account in Safari.
If you can, the next step is to check whether an unsuccessful Yahoo account setup is already present on your Mac.
Open Apple menu >> System Settings >> Internet Accounts.
If a Yahoo account appears there but was not successfully configured, you can remove it before trying again.
Apple explains how to add, manage, and remove Internet Accounts here: Use your internet accounts on Mac. (Apple Support)
You can then add the account through Mail >> Add Account or System Settings >> Internet Accounts >> Add Account.
When Yahoo is available as an account provider, select Yahoo and follow the information requested during the sign-in process.
Apple documents this procedure here: Add and manage email accounts in Mail on Mac. (Apple Support)
The password you created at Yahoo and named “Mac Mail” is a Yahoo app password.
It is intended for situations where a third-party email application requires an app-specific password rather than Yahoo's normal sign-in process.
Therefore, it is best to follow the sign-in method requested when you select Yahoo as the account provider rather than entering the app password unless Yahoo or Mail specifically requests it.