How real is it to become a "formal" researcher (that is someone holding some research position) after earning a PhD at the age of 40? Sometimes it so happens that people discover their true interest only later in life. But because society is used to follow certain established patterns, it may be difficult for such people to readjust their lives. I believe there exist certain biases or prejudices about what people are supposed to do at a certain age, which may hinder one's path socially, emotionally, as well as professionally.
It depends a lot on the field you are in. In some fields, almost everyone who ends up being a professor has had a previous career outside academia. An example is education where your previous background will be considered a plus and there is no stigma attached to being older.
But there are also fields where yours would be a very uncommon career trajectory and where people have the perception that researchers' best contributions come when they are still young. Mathematics would be an example. In these fields, you will probably have a harder time finding a career as a researcher in academia, though I suspect that it makes little difference if you are going for an industrial research position.