By "shared and optimized on iCloud", I am assuming you have enabled the iCloud Photo Library. The quickest and most foolproof way I know for sure is using a Mac computer running a recent version of MacOS. Using the default Photos program (now a part of the OS components), sign it into your iCloud account, set it to sync to the corresponding Photo Library and you should be able to see all your photos. From there you can export them to local storage. Make sure you have saved all before doing any change to the Photo Library: it is a cloud-based service, is the ONLY copy of your pics, and any deletions propagate immediately.
I suppose something similar could be done in the Windoze world, but I have no experience or knowledge of how to do it.