How to secure my Mac again after years of downloading pirated software?
A recommended course of action would be to backup your user data (data files that you have created, not the apps and their settings) onto a different (external) drive, wipe your Mac clean and start over. This could be the most sure-shot way to ensure that your computer is free of any/all malicious apps/permissions/plug-ins.
When backing up the data, make sure you backup all the crucial files as well as app and system configurations (such as browser bookmarks, info about any installed plugins, contacts etc.)  and don't miss anything. Files can be copied onto a different external volume, browser bookmarks and any similar data from apps exported (for later import), user data such as Notes, Contacts, Reminders synced via iCloud etc. However, do not backup any apps/plug-ins etc.
Another important tip is to not use any data backup service such as Apple's Time Machine or something similar from a 3rd party that backs up and restore the entire system. Doing this wouldn't serve the purpose you are looking for. It's crucial to handpick and selectively backup only the user data files. Any apps that you are using, and wish to use should be re-installed after the fresh install of macOS, from the Mac App Store or from the vendor's original distribution source.
Once all the backup is done, and you are sure you have everything that you'd be needing, you should go ahead and create a bootable macOS installer. A working Mac is required to create a bootable macOS installer. So we'd be doing this before wiping the disk clean. This would ensure that we have a bootable installer handy if needed after we have wiped the disk clean and have lost access to an installed copy of macOS.
The step by step instructions to create a bootable macOS can be found here:

How to create a bootable installer for macOS

You should also sign out of iCloud (after making sure any data that backs up to iCloud is successfully synced) and turn-off Find My Mac. Doing so would disassociate your Mac from your Apple ID. For a comprehensive list of actions to take, you can refer to the following Apple Support document:

What to do before you sell, give away, or trade in your Mac

Now the data backup is taken care of, we are ready to wipe the disk clean. Be doubly sure about backing up any necessary data as wiping the disk clean would make you lose access to the entire installation and any data on your MacBook's disk.
Proceed ahead to erase your Mac's disk to wipe it clean. You can find the step by step instructions here:

How to erase a disk for Mac

Alternatively, you can also boot your Mac using the bootable USB installer that we created earlier, access the Disk Utility and wipe the internal drive.
Once you are done erasing the disk, proceed ahead to reinstall macOS afresh. You can use the bootable installer that we created earlier on.
Alternatively, if you have a decent Internet connection, and if your Mac supports it, an Internet Recovery can be attempted too. (I would personally recommend going with the bootable USB installer.) To learn more about Internet Recovery, refer to the Apple Support document:

About macOS Recovery.

Once you are done installing macOS, signing-in with your Apple ID and setting up your Mac, you can start by installing the required apps. Two reliable sources to obtain Apps are:

Mac App Store (built into macOS).

Homebrew and Homebrew Cask (A community developed package manager for macOS, which lets you easily install and manage UNIX command-line tools, and popular 3rd-party GUI apps respectively).


You can now start restoring your data:

Once iCloud is enabled, any data that syncs to iCloud would get restored onto the system. Go to System Preferences app → Apple ID → iCloud (On macOS Catalina) or System Preferences app → iCloud (On earlier releases of macOS) and check what apps you wish to sync with iCloud. The checked apps would sync their data to the system.

Restore by importing, any app data that you previously backed up by exporting (such as browser bookmarks).

Any app and their plugins that can be obtained from the developer's website/source of distribution should be installed from the original source.


If an app that you use doesn't have a free alternative available, prefer purchasing from the vendor and installing a non-pirated version to ensure that your computer doesn't get compromised and you have a complete peace of mind.
P.S.: If you are concerned about rouge apps getting unintended access to your personal data and wish to guard your self against it, consider installing macOS Catalina, the current latest release of macOS. macOS Catalina has improved security and a permission-based system for apps to access user data and files (kinda similar to iOS).
One major downside of using macOS Catalina could be that it has completely dropped support for 32-bit apps. While a majority of supported apps are 64-bit now, you may still wish to consult with app vendors to see if they offer a 64-bit version of their app that you wish to use, and there's no alternative available for the same. If such becomes the case, you may consider sticking with the last stable release of the previous version of macOS, i.e. macOS Mojave 10.14.6 which is well supported too.
But since you are concerned about the safety of your data and rogue apps, you should give serious thought to go with macOS Catalina. This article on WIRED sheds some light:

The MacOS Catalina Privacy and Security Features You Should Know