Cell identification by Body Cells
Broad question. Summary:

The innate immune system processes everything. When it senses that something is dangerous it tells the adaptive immune system, that is T and B cells, that this thing I'm holding is dangerous (via coreceptors and cytokines). 

T and B cells that are specific for this dangerous protein (or sometimes non-protein) are activated. 

Ideally T and B cells that react to self proteins are deleted. These are from central tolerance mechanisms when the cells are developing (T and B cells are tested against self proteins; if they react they die) and in the periphery (once they're mature) by them only getting activated by the innate immune system and other mechanisms. There's also T regs which regulate the immune system by preventing any cells that react to self proteins from being activated. 

Autoimmune disorders are caused by a break down of these mechanisms.