You could forfeit your earnest money, depending on how the contract was written and why you decided to back out. The earnest money could be 1-2% of the sales price of the home.
Buying and selling at the same time can be complicated but doable. The key is having an experienced realtor to assist you with strategy, timing and negotiation.
A mortgage is a loan that can be paid off over 15 or 30 years to finance a property.