I would like to go to America for 3 months for holiday. Then I should spend 2 months working on a temporary resident work visa in Canada. And finally I want to spend some more holiday in America for another 3 months. Am I allowed to follow this itinerary?
Yes, that should not be a problem.
Make sure you have a tourism visa or an ESTA if you are a national of a Visa Waiver Program country. Also make sure you have a clear itinerary and a proof of it before crossing the borders, a temporary resident visa for the first USA entry and a plane ticket for the second USA entry should be enough, as the border agent has the job of determining if you are allowed to enter.
Also remember that the maximum stay as a tourist is 90 days (not exactly 3 months), avoid overstaying as it may result in being banned from reentering for some time.
If you are a VWP national, the "90 days North America counter" rule is not supposed to apply because you will be a resident of Canada. However, as @cpast mentions in a comment, the US embassy in Canberra recommends a tourist visa (B1/B2 Business/Tourism) for trips to the USA as a temporary Canadian resident (e.g. on a Work Holiday visa or student permit).