When marginal revenue (MR) and marginal cost (MC) are equal, the firm has maximum profits.
Marginal revenue is the revenue generated by selling an additional piece of the commodity. Marginal cost is the cost of producing or manufacturing an additional unit of commodity. In general, the marginal revenue is same as the price of a commodity. For example, if one piece of an item sells for $20, two will sell for $40 and hence the marginal revenue is $20. On the other hand, any cost associated with generating an additional unit (this may also mean setting up an additional factory or hiring more workers, etc) is counted towards marginal cost.
If MR > MC, then each additional unit means extra revenue or profit and thus firm should produce more units.
If MR < MC, each extra unit will mean extra loss and hence the firm should produce less.
Therefor the optimal production would be at MR=MC level, where the profits will also be the maximum (since an extra unit will not mean extra profits or loss).
Hope this helps.