I hope I'm not too incorrect with my terminology and Christianity in general here...
So according to the Bible, Jesus' final words were "Oh Lord, why have you forsaken me?"
But, in the tradition of the Trinity, Jesus is both God and his son (and the holy ghost), and moreover, Jesus is the lord. So, essentially, what Jesus said before he died was "Oh me, why did I do this to myself?" Is this correct?
Are you asking what the historical Jesus meant, or what orthodox Christian theology holds that he meant? The two are not the same.
On the former, assuming that Jesus really said it - which there is no reason to doubt - it's a quotation from Psalm 22. It could be seen as an expression of despair. There's no reason to suppose that the historical Jesus believed himself to be divine, let alone identical to the Father, so there's no reason to suppose that he was addressing himself.
On the interpretation of this saying in the context of orthodox Christian theology, I think you've misunderstood the doctrine of the Trinity. According to that doctrine, Jesus is absolutely
not identical with the Father, or with the Holy Spirit. Each of the persons is God - and they are the same God - but they are nevertheless distinct. To say that Jesus is identical with the Father is the heresy of modalism. So in this saying, Jesus - the Son, the second person of the Trinity - addresses the Father, the first person of the Trinity. He is not talking to himself. The same goes for all the many instances in the Gospels where Jesus prays to the Father.
Furthermore, since Jesus is the Lord and the Lord possesses both omniscience and omnipotence, couldn't Jesus have avoided the whole debacle with the Pilate all together since he had foresight of the event? Why did he have to be crucified?
If he
was omnipotent and omniscient, then presumably he could have avoided it, but chose not to. But Christian theologians do not all think that he was omnipotent and omniscient. And some think that although he was omnipotent and omniscient, he didn't know that he was, so he was effectively not omnipotent or omniscient.
As for why he had to be crucified, again if you are asking that from a theological point of view rather than a historical one, then that's the doctrine of the atonement.
But I think we've addressed these issues before, one way or another, if you have a look at the index at the start of the thread.
I am not the expert, but I am pretty sure the new testament predates the idea of the trinity. I think the idea grew out of a couple of Paul's ramblings.
I don't know what you mean by "ramblings", but I don't think that it's a particuarly Pauline idea or associated with Paul more than any other biblical author. Obviously the Trinitarian formula comes from Matthew.
What are your thoughts on potential connections between early christian heresies and similarly named medieval heresies.
It depends on what heresies you're talking about. Some medieval heresies
may have had historical connections to ancient ones, the obvious example being Catharism and gnosticism, but there's no real evidence for any historical link. Some less dramatic heresies were certainly identified by their opponents as resurgences of ancient ones. For example, the Spanish adoptionists were accused of being Nestorians, Abelard was accused of being a Pelagian, and so on and so forth. In this case, the medieval "heretics" would certainly have been aware of the ancient heresies of which they were accused, so there's a historical connection in that sense. But it seems pretty unlikely that they were positively influenced by them. Rather, their opponents interpreted them through the lens of ancient doctrinal controversies. For example, Alcuin of York read the works of Felix of Urgel and thought he saw Nestorianism in them. Whether Felix really said anything like Nestorianism is uncertain; even if he did, whether he got the idea from the ancient Nestorians seems unlikely. The same goes for Abelard and Pelagianism.