I want to save all my photos to iCloud and then delete them from my iPhone. How do I delete them from the iPhone while still keeping a copy on iCloud?
iCloud is a syncing system and not a just a backup.
If you delete the pictures on your iPhone (assuming you're logged into the same iCloud account) you're also deleting the pictures in iCloud. This is not what you want to do.
Find a backup solution to keep your photos like Dropbox or Amazon Photos. Those will allow you upload your images without keeping them on your other devices.