Gender identity first, definitely. I had gender issues long before I had any idea what sex was.
The gender identity/body dysmorphia stuff combined with an unrelentingly homophobic upbringing left me with a lot of ambivalence towards sex and I had no clear orientation - at least not that I was willing to embrace.Accepting my gender identity has freed me up to admit that I might <gasp> like guys.
:D