How long after graduating can I use my former professor as a reference?
There is no hard limit, other than the professor being alive.

Generally, it is useful to include only references that are relevant and can express something about your current abilities. So, if a professor can say something meaningful and relevant about you, even after a decade or more, then you can include them as a reference.

If, however, your abilities and skills have significantly changed in the respective area (e.g. you gained substantially more experience in this particular field), then the reference is outdated, and it is better not to include them.