Anatomy of thought
The cerebral cortex (cerebrum) of the brain is responsible for human thought. It is divided in two hemispheres and four lobes, each of them performing various functions, such as cognition, complex thinking, reading, speech etc.
The case of Phineas Gage is a good example of sensation and perception being intertwined, yet clearly distinguishable, separable human faculties.
Cerebral cortex (cerebrum)
What distinguishes us from animals is the cerebral cortex, short: cerebrum. It's the youngest part of the brain in contrast to the reptilian brain (vital functions) and the limbic system (emotions). The cerebrum fills most of our skull and apart from fundamental tasks such as vision, hearing and muscle control it is responsible for abstract, mental faculties such as remembering, problem solving, planning and higher thought processes such as thinking, reading, learning and speech. It also contributes to emotions along with the limbic system.
Where thoughts come from
Admittedly, science doesn’t know where thoughts really come from. One could argue that thoughts emerge from everywhere, naturally from neuronal processes or that they just pop up in our heads as a result of random chance. But this only seems vague and doesn’t really explain the causes. Currently, science is not in a position to make any final statements about the ultimate causes of the thought processes because we don’t know enough about the actual wiring structures and the quantum processes in the brain. The research continues.