I know how to query all the attachments related to the opportunity, but how to do the same for files attached. Seems like a file is a part of a content library.
Solved. The file is actually a content document and could be easily obtained via foreign key:
SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '<Opportunity or other object id here>'