In the novel The Brothers Karamazov, did the writer take those characters out of real life? Or did he just build the characters with time?
My source for this answer is "A Karamazov Companion" by Vitor Terras (1981), University of Wisconsin Press.
The Brothers Karamazov contains more autobiographic elements than most of Dostoevsky’s works (...)
Let's go through some of the characters.
It seems that Aliosha was based on people from real life.
Aliosha Karamazov’s image is designed on the pattern of a saint, specifically Saint Alexis. These correspondences are made quite explicit in the novel
In a footnote for this sentence:
Vetlovskaia suggests that these correspondences relate specifically to the folk version of the life of Saint Alexis. Thus, Dmitry at one point calls Aliosha (a tall young man) “ a little man,” which is the epithet fondly given Saint Alexis in the folk legend. Grushen’ka calls Aliosha a “ prince,” which Saint Alexis is in the folk legend. The name of the saint’s bride in the folk legend is either Katerina or Lizaveta. A girl named Lizaveta is mentioned at the same time that Saint Alexis first comes up in the novel (Book Two, chap, iii, p. 44)—while Aliosha and Liza Khokhlakov are also present. Vetlovskaia points out many other such details.
However, Dostoevsky's wife thought Aliosha's character was also inspired by their son with the same name, who died before Dostoevsky started writing the novel.
(...) together with the name, all of a father’s tenderness, all the unrealized hopes for his son’s brilliant future, were transmitted to the novel’s young hero.
Despite some theories, it seems that the father Karamazov's character was not based on Dostoesky's own father.
At least since Sigmund Freud’s famous essay “ Dostoevsky and Parricide ,” 65 many people have assumed that Mikhail An dreevich Dostoevsky, the writer’s father, was the prototype for Fiodor Pavlovich Karamazov. But the only trait which connects them is the family tradition—never verified by Dostoevsky him self and quite possibly false—that Mikhail Andreevich was mur dered by the peasants of his village, Chermashnia, who alleg edly resented his carrying on with their women. Other than that, Dr. Dostoevsky bore little resemblance to Fiodor Pavlovich. He was not a colorful character, and he was by the standards of his day a good father. The commentators of PSS quite properly reject this connection .66
So it is uncertain if Fiodor was inspired by anyone specific.
This is in contrast with Dmitry Karamazov character, since he:
(...) has a real-life prototype in a sublieu tenant, Il'inskii, whom Dostoevsky had met in Omsk prison. The first sketches of this character still bear Il'inskii’s name.
Like the novel's character, Il'inskii's also
was convicted for parricide but denied that he had done it, despite overwhelming evidence against him
Torres also explains that both of them have similar personalities.
Zosima's character seems to have been inspired by a number of different people:
There is Father Amvrosy (1812-91), whom Dostoevsky had visited at Optina Pustyn' in 1878.71 The monastery and Zosima’s cell are patterned after Optina Pustyn' and Father Amvrosy’s cell.
Father Zosima of Tobolsk (1767-1835), whose secular name was Zakhary Verkhovsky, had a biography reminiscent of Zosima’s .
Even more important is Tikhon of Zadonsk (1724-83).75 Linnér compares Zosima with the historical Tikhon and finds that, while Zosima has inherited many of Tikhon’s traits, he is also different (...)
There are a number of other possible prototypes for Father Zosima
Ivan doesn't seem to have been inspired by anyone specific but
Braun is probably right when he suggests that Ivan is “an independent, creatively formed personage, with the author himself, as well as some other individuals (Belinsky, for instance), serving as a model.”
Elizaveta, Grushen'ka, Rakitin and the laywer Fetiukovich might also be inspired on real people:
Dostoevsky’s brother Andrei Mikhailovich identifies a retarded girl named Agrafena as the prototype for Elizaveta Smerdiashchaia
A young woman named Agrippina (“ Grushen'ka” ) Men'shov, mentioned in Dostoevsky’s letter to his wife of 25 July /6 August 1879 (Pis'ma 4:76), may be the pro totype for Grushen'ka Svetlov, whose Polish ex-lover insists on calling her Agrippina, instead of Agrafena or Grushen'ka.
Rakitin is drawn after Grigory Eliseev (1821-91), a journalist whose biography was more or less that which Ivan projects for Rakitin.
The lawyer Fetiukovich is a composite drawing of several liberal lawyers, Vladimir Spasovich (1829-1906) in particular
I haven't found any evidence, that any of the characters are taken from the real life. Researchers point some character inspirations from the real life but these are just theories. And yes, Dostoevsky did build and develop the characters while creating the novel. Russian's Wikipedia featured article on the topic is rather comprehensive, I don't know about any resources about it in English.