Make sure that your router is configured that it will allow traffic from the internet to acces the server that is running Openfire. This typically involves port forwarding.
Register a domain name, and have DNS records that make that domain name resolve to your external IP address.
Make sure that your server is reachable by that domain name from the internet. This typically involves setting up DNS (A) records.
For ease of use, configure Openfire to use the same domain name. The easiest setup is to make your XMPP domain name equal to the domain name that you use for your host (eg: both “example.org”). You can, however, easily differentiate. Typically, you see that the hostname of the server that is running Openfire then is assigned a FQDN that is a subdomain of your domain (eg: “openfire.example.org”). In this case, you’ll need to set DNS (SRV) records to provide the mapping.
Obtain a CA-signed certificate for your domain. Ensure that the certificate covers at the least the XMPP domain name as well as the FQDN of the host that’s running Openfire (again, if these are the same, things are easier). You can use Let’s Encrypt for this, which is free, but more complex to set up. Best results are obtained with a wildcard certificate for all subdomains of your domain.
Ensure that on your LAN, you can use the same domain names, reaching the same server and service (you can use different IP addresses internally - Openfire cares little about those).
After your network is properly configured, setting up Openfire is pretty straightforward. Run the setup wizard, and make sure that you use the correct XMPP domain name and FQDN values. Spark should run pretty much out of the box, provided that you’re using properly signed certificates.