There are limits to the quantity available of every resource that is utilized in the economy. This is what leads to all goods and services having a price. If there was no scarcity of resources, everything would be available for free.
Opportunity cost is related to scarcity as neither the consumer nor the producer has an unlimited resource of anything. Whenever any transaction is carried out each party gives the other something that they have a limited quantity of.
For example consider a person buying a car. The buyer is spending money that could have been instead used each time the person hired a taxi. By using a taxi the person would not have to drive the car herself and would be assured of reaching the destination without putting in any effort. The opportunity cost of buying the car is the services provided by a taxi. Only if the buyer feels that the utility of having a personal vehicle is more than the utility of using a taxi does it make sense to buy the car.
Similarly, the car dealer is given some money by the buyer for the car. The opportunity cost for the dealer here is, as an example, the amount that the car would have been sold for had it been exported. If the dealer would have got a price for the car that is more than what was spent in transporting the car to the foreign buyer, it does not make any sense to sell the car to this buyer. The excess that the dealer could have earned is the opportunity cost of selling the car here.
Opportunity cost is important in economics because it helps in making decisions based on which choice has the highest value and which choice has to be given up. In child terms, if you want to go to the baseball game, but also want to go to your friend's birthday party, you will have to make a decision or give something up. Opportunity cost is found by comparing the benefits of each choice and choosing the one with the highest value. Whatever choice you do not go with, is the opportunity cost.
Scarcity means there is a shortage of economic goods and the needs/wants of people are not able to be fulfilled. For example, different kinds of fruit become scarce during certain times of the year. Scarcity also pinpoints a possible high demand for a product.