How could I get a selection set of GameObject sharing a material or a script in Editor?

Materials and scripts could be referred as components. Should I write an editor script searching through every component of every gameObject collecting them, or is there a built-in function? Or should I put them onto layers at the beginning?

Materials and scripts could be referred as components.

Not sure what you mean by that, but you should be able to do what you're wanting using an editor script, I think. For materials, you'd probably need to iterate over all renderers to see which ones reference the specified material, and for scripts, you'd simply need to find all game objects that included the specified script. (There's a function called FindObjectsOfType() or something of that sort that you should be able to use to return all renderers or components of a specified script type.)