I will keep the answer short and pray that it is sufficient. Whilst much can be said the simple answer is that the primary function of people is to please Allah Subhanahu Wa Ta'ala. And This is done through worship, refraining from sins and living life in accordance with Shariah.
Allah Ta'alah States (51/56): وما خلقت الجن والإنس إلا ليعبدون [We did not Create Man or Jinn exept that they worship]