Yes, you can run a web server and a mail server on the same Ubuntu machine. That's a pretty common setup.
You will need:
- host OS (Ubuntu is fine) with a static public IP address
- firewall on your host OS (eg. combination of iptables with UFW on top)
- registered domain and access to DNS server to change/add DNS records (for MX records as you mentioned)
- webserver (apache is fine), programming language (PHP in your case), database (I assume MySQL or maybe MariaDB) for running your WordPress website(s)
- mail transfer agent (postfix is fine), mail delivery agent (dovecot is fine) for running your mail server.
Additionally you might want to have:
- full-text search (eg. using Solr) and spam filter (eg. using Rspamd) for your mail server
- SSL certificate(s) for encryptet access to your website(s) and your mail accounts (eg. using Let's Encrypt / certbot-auto).
- automatic security updates (eg. install unattended-upgrades)
Mail server setup:
Setting up a mail server correctly is a pretty complex task. There's a lot you need to know (like DKIM, DMARC, and SPF) so other mail servers will trust you and your e-mails won't end in your receivers' spam filter.
Luckily there is this excellent guide from Cullum Smith: How To Run Your Own Mail Server
You only need one instance of a web server software, for example Apache, to server multiple websites. But there are configurations possible where you would in fact use two instances of web server software, like Apache AND nginx on the same machine. But that has nothing to do with running a mail server. People install this combination of Apache & nginx for performance and security reasons – like nginx handling the external communication, talking to the internet real fast and secure (called a reverse proxy) and apache handling the internal communication, to PHP, MySQL and your website's files.
Your mail server won't have contact to your Apache instance (unless you plan to implement webmail access).