IUPAC of heterocyclic compounds terminology
This way of naming heterocycles is known as the Extended Hantzsch-Widman system of nomenclature (the above link is a free reproduction of a publication that revised this system : W.H. Powell, Pure Appl. Chem., 1983,55, 409-416). 

The stems do actually come mainly from numeric prefixes. " 'ir' from tri, 'et' from tetra, 'ep' from hepta, 'oc' from octa, 'on' from nona, and 'ec' from deca."Source. They are mainly taken from the middle letters of the numeric prefixes. As for "ol" and "in" for 5 and 6, these are holdovers from the intial system from 1887 that was developed for nitrogen containing rings, so my guess is they were kept to maintain the connection to the endings of pyrrole and pyridine.