How to find out whether a plugin is used in pages or posts?

You are looking for:

is_plugin_active( string $plugin )

This function takes a string parameter that is the representation of the path to the plugin relative path in the plugins directory.

So your practical implementation would look something like this:

<?php

if(is_plugin_active('elementor/elementor.php') || is_plugin_active('woocommerce/woocommerce.php')){
    // Do something, remove scripts etc..
}