The first approach that comes to mind is to create a temporary in-memory solid representing the opening geometry.
You can use that solid to define an intersection filter and retrieve all elements that clash with that.
The Building Coder discussion on using an intersection filter for linked elements shows you all the required steps and more besides:
https://thebuildingcoder.typepad.com/blog/2018/12/using-an-intersection-filter-for-linked-elements.h...
One way to detect the exact intersection surfaces where the clashing element enters and exits the opening geometry would be to project its geometry onto the front and back opening surfaces an use a 2D Boolean operation on that:
https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.2
You can probably also achieve the same using the ExtrusionAnalyzer class:
https://www.revitapidocs.com/2019/ba9e3283-6868-8834-e8bf-2ea9e7358930.htm