Calculus and heat flow in metric measure spaces and applications to spaces with Ricci bounds from below