Actually, in both sentences "es" is the subject and "mir" the indirect object. The verbs are intransitive*, meaning they have no direct object. Since the self is the beneficiary of the operative verb's action (gefallen, to please; lit. "it pleases me"; fig: "I like it") it gets the Dative.
*) In fact, you can use them without any object (i.e. "Es gefällt."; lit.: It pleases.; fig.: They like it.)