The code will be quite heavy from a performance perspective. You'd look to:
- Get the Components
- For each Component, Where Used, filter for Pages (heavy)
- For each Page, see if it is published to a target (medium)
- Add to a list for processing later...
To Get the Components you could decide to do it either with the SearchAPI or the normal recursive GetListItems.
If you're performing this over hundreds or thousands of items, you might consider first creating the list of Components in an external datasource, such as SQLite, CSV file, XML file, etc. Then, when processing the Components, mark each completed one as processed, and that way if the script stops for any reason, you can start back with the next item.