I dont quite understand how this is all calculated, if a runner reaches base on an error and if he scores it is unearned, but what if the runner advances a base or scores on a error does this run count as an earned run? and is it true that any run scored after 2 two outs and an error is unearned?

If a runner reaches on an error it is unearned. if the runner advanecs or scores on an error is unearned.yes it is true that if theirs an error with 2 outs its unearned BUT thats the scorekeepers deciocon if the fieleder can get the out. Example: In a Braves game Adam LaCorache or w/e with 2 outs got a grounder and walked back to 1st base and the runner beat him. So the next 4 runs the other team scored were unearned.

Runs are unearned if you replay the inning turning errors into outs and the runs would not have scored.