Soap is created by the hydrolysis reaction of a fat. Usually sodium or potassium salts are used to create soaps and the reaction that takes place is the following: XOH + fat --> glycerol + X salt of fatty acid.
Soap can be used as a cleansing agent due to the presence of a polar and a non-polar functional group. It is not possible to clean grease, oil or other non-polar substances using soap due to the fact that water is polar in nature and the impurities are repelled by water.
When soap is added to water, the non-polar end of the soap molecule links to the polar impurity like grease and the polar end links to the water molecule. This creates a bond between what is required to be cleaned and water. As a result water and soap can be used to to clean polar as well as non-polar substances in a very effective manner.