Identifying packages which are no longer available
The most useful tool to list packages which need to be checked in this situation, is
apt-show-versions. Install that, then run it as follows:
apt-show-versions | grep "No available version in archive"
to list all packages which aren’t available at all with your current repository configuration (and should be removed).
apt-show-versions | grep "newer than version in archive"
to list all packages whose currently installed version is newer than the versions available with your current repository configuration (and which you might wish to downgrade).
You can obtain similar information using
apt list --installed and looking for
[installed,local], but that doesn’t distinguish between packages which aren’t available from your configured repositories and packages which are available, but in an older version than the currently installed one.
aptitude can show you this too; start it and look for the “Obsolete and Locally Created Packages” section in the TUI. That will contain all the packages which aren’t available from your configured repositories. You can list the packages using
aptitude search '~o'
in your shell too.
Deleting packages which are no longer available
aptitude provides the simplest answer to your actual question:
aptitude purge '~o'
will purge all “obsolete” packages (i.e. packages which are no longer available from the repositories).
Identifying and deleting contrib or non-free packages
aptitude can also identify contrib or non-free packages without needing to remove the corresponding repositories:
aptitude search '~i ~scontrib/.*' '~i ~snon-free/.*'
You can purge them directly:
aptitude purge '~i ~scontrib/.*' '~i ~snon-free/.*'