On your specific example of Avraham having taught math and astronomy to the Egyptians, Prof. Annette Yoshiko Reed in her essay "Abraham As Chaldean Scientist and Father of the Jews: Josephus, "Ant." 1.154-168, and The Greco-Roman Discourse About Astronomy/Astrology", pg. 123, wrote:
"In addition, a number of scholars have pointed to the Hellenistic Jewish precedents for Josephus' expanded account of Abraham's Egyptian sojourn (e.g., Artapanus, Pseudo-Eupolemus) and have cited these examples to illustrate his overall indebtedness to Hellenistic Jewish "apologetic historiography".
In other words, Josephus based himself on the accounts of prior Hellenistic Jewish historians (of whose works we only have fragments quoted by later authors, such as Josephus and Eusebius).
For example:
Eusebius in "Praeparatio Evangelica", Book 9, quoted in relation to this passage by Josephus from Alexander Polyhistor's "Concerning the Jews":
"And with this agrees also Alexander Polyhistor...in the thirteenth generation Abraham was born, who surpassed all men in nobility and wisdom, who was also the inventor of astronomy and the Chaldaic art, and pleased God well by his zeal towards religion. By reason of God's commands this man came and dwelt in Phoenicia, and pleased their king by teaching the Phoenicians the changes of the sun and moon and all things of that kind. And Abraham dwelt with the Egyptian priests in Heliopolis and taught them many things; and it was he who introduced astronomy and the other sciences to them, saying that the Babylonians and himself had found these things out, but tracing back the first discovery to Enoch, and saying that he, and not the Egyptians, had first invented astrology."
And then he brings from Artapanus of Alexandria's "Jewish History":
"Artabanus in his Jewish History says that the Jews were called Ermiuth, which when interpreted after the Greek language means Judaeans, and that they were called Hebrews from Abraham. And he, they say, came with all his household into Egypt, to Pharethothes the king of the Egyptians, and taught him astrology."
And in Book 13 quotes Orpheus:
"And again concerning God, calling Him invisible, he says that He was made known only to one certain person, a Chaldaean by birth, whether he so speaks of Abraham, or of his son, in the following words:
"Save one, a scion of Chaldaean race:
For he was skilled to mark the sun's bright path,
And how in even circle round the earth
The starry sphere on its own axis turns,
And winds their chariot guide o'er sea and sky.""
Philo also makes mention of Avraham having prior astrological knowledge in "On Abraham":
"And the most visible proof of this migration in which the mind quitted astronomy and the doctrines of the Chaldaeans, is this. For it is said in the scriptures that the very moment that the wise man quitted his abode, "God appeared unto Abraham," to whom, therefore, it is plain that he was not visible before, when he was adhering to the studies of the Chaldaeans, and attending to the motions of the stars, not properly comprehending any nature whatever, which was well arranged and appreciable by the intellect only, apart from the world and the essence perceptible by the outward senses."
However, it does not appear that the Hellenistic Jews invented this tradition, or at least not entirely. For example, we find in the Book of Jubilees (written prior to Josephus, perhaps the mid-2nd century BCE):
"And in the sixth week, in the fifth year thereof, Abram sat up throughout the night on the new moon of the seventh month to observe the stars from the evening to the morning, in order to see what would be the character of the year with regard to the rains, and he was alone as he sat and observed.
And a word came into his heart and he said: "All the signs of the stars, and the signs of the moon and of the sun are all in the hand of the Lord. Why do I search (them) out? If He desireth, He causeth it to rain, morning and evening; And if He desireth, He withholdeth it, And all things are in His hand." (12:17-19)
and a hinted past observance of the stars in the Apocalypse of Abraham (written circa Josephus, likely based on older material):
"Nor will I place among the gods the one who obscures his course by means of the moon and the clouds. Nor again shall I call the moon or the stars gods, because they too at times during the night dim their light. Listen, Terah my father, I shall seek before you the God who created all the gods supposed by us (to exist). For who is it, or which one is it who made the heavens crimson and the sun golden, who has given light to the moon and the stars with it, who has dried the earth in the midst of the many waters, who set you yourself among the things and who has sought me out in the perplexity of my thoughts?" (7:8-11)
and, l'havdil, we also have midrashim from our sages about Avraham's astrological/astronomical knowledge:
Shabbat 156:
"Abraham said before Him: Master of the Universe, I looked at my astrological map, and according to the configuration of my constellations I am not fit to have a son. The Holy One, Blessed be He, said to him: Emerge from your astrology, as the verse states: “And He brought him outside,” as there is no constellation for Israel. What is your thinking? Is it because Jupiter is situated in the west that you cannot have children? I will restore it and establish it in the east. And that is the meaning of that which is written with regard to Abraham: “Who has raised up one from the east, he will call justice [tzedek] to his steps [leraglo]. He gives nations before him, and makes him rule over kings; his sword makes them as the dust, his bow as the driven stubble” (Isaiah 41:2). God established Jupiter [tzedek] in the east on behalf of [leraglo] Abraham."
Beresheet Rabbah 44:
"And He took him outside, Rabbi Yehoshua of Sichnin in the name of Rabbi Levi [said]: "Did He take him out of the world, as it says: "And He took him outside"? No, He showed him the streets of heaven, "where is what you said, "He had not yet made earth and fields"", said Rabbi Yehudah in the name of Rabbi Yochanan: "He raised him above the dome of the expanse, as He said: "Look at the sky", the use of habatah indicates a looking down from above. the sages said: "You are a prophet and not an astrologer", as it says: "Therefore, restore the man’s wife—since he is a prophet.""
Josephus himself also claims this idea can be found in Berossus's writings:
"Berosus mentions our father Abram without naming him, when he says thus: "In the tenth generation after the Flood, there was among the Chaldeans a man righteous and great, and skillful in the celestial science."" (Antiquities 1:7:2)
I'll also note that ancient astrology involved many complicated mathematical calculations and knowledge of the stars, so if Avraham was an astrologer at one time, then he must have also had knowledge in mathematics and astronomy.
From all of this, we may say that likely Josephus received most of his extra-Tanachic knowledge about the Patriarchs from earlier historians, both Jewish and non-Jewish, and perhaps also got some information from the texts of other Jewish denominations, or from word-of-mouth from Jews of these other groups.