I know about Hanibal and his war elephants but I'm interested to know if there were any ancient cultures who used elephants to help build structures or help out with agriculture etc. Bonus question, with all the research about elephants mourning their dead and other traits which stand as testament to their intelligence were there any ancient cultures who recognised the intelect and "emotions" of elephants?
The Indus valley civilization was among the earlier ones to domesticate elephants. ( I think even earlier dates of ~6000 BC have been suggested based on cave paintings). Elephants would have been used for forestry/logging/hauling heavy loads, in addition to ceremonial, religious purposes and for war.
There is a wealth of literature in India on the art of capture and care of elephants, including Matanglila from ~5th century BC (also talks about their physical and mental characteristics), Hasthi ayurveda on medical care of elephants. Kautilya's arthasastra (on statecraft) recommended setting up of elephant sanctuaries and rules for killing and capturing as well as positions for the training and care of the elephant
Obligatory comment: Elephants have been tamed and used in war, transport and labor many times, mostly in India and southeast Asia, where they are still in use, and to a lesser extent in the Mediterranean world and China (plus possibly in Nubia (Ancient Sudan) and an experimental attempt in the Belgian Congo around 1900). They have never, however, been domesticated. Domestication implies the controlled breeding and artificial selection of plants and animals until the behavior, biology and often aspect of the domestic form is noticeably different from its wild ancestor. Because elephants are intelligent animals but breed rarely in captivity, in ancient times it was easier to simply capture them from the wild and train them (or buy them in a place where trained elephants were more common).