Within queer, trans*, LGB, and (some) feminist circles, sex is the formation your genitals appear, usually male or female, but there’s a good amount of discussion on if there’s such a thing as “a sex” when given the option for intersexed people. Gender is more what’s in your head (hence the phrase “gender is between your ears, not your legs”), however, what exactly it is in your head is up for some debate. I think it’s Simone de Beauvoir who came up with the differentiation between sex and gender when she said “One is not born, but rather becomes, a woman” (though, because de Beauvoir was French, the translation is not perfect, and the technical split is one of language), and then Judith Butler who gave the idea a renaissance, and it has since become largely accepted. So, transgender people are those who do not feel that their sexual identity (what’s between their ears) matches up with the genital formation they were born with, but who may or may not have made any physical changes to deal with this; transsexual people are only those who have changed their physical body in order to bring their sex and gender into more alignment. I personally just go with trans* most of the time.
I wouldn’t say it’s really accurate or acceptable to use gender when referring to biological sex, unless the purpose is to refute the validity of trans* and queer people and promote the idea that there cannot be a split between the sex you were assigned at birth and what gender you “really are”.