How do I delete photos from Apple Photos retaining only those marked as favorite?
You can do this using smart albums.
Unfortunately the gif I made to show this is to big so pictures will have to do.



go to all your photos and select all of them (cmd+a).
Create a new smart album for your selection

In the popup select photo is not favorite as filter, you should see the number of matches.

In the smart album are all your photos not marked as favorite, select them all (cmd+a) and delete them (cmd+backspace).

Go to all your photos, only the favorites remain.

Empty the trash in the photos app to remove all deleted non favorites.