George Lucas originally conceived the idea to have Anakin Skywalker build C-3PO shortly after the original Star Wars movie released in theaters in 1977. Even though the original movie (which was only later renamed A New Hope) debuted in a handful of theaters, it was later expanded nationwide and became one of the most successful movie releases of all-time. So, it was no surprise that Lucas and the studio, 20th Century Fox, wanted to move forward with a Star Wars sequel.
Lucas' Star Wars sequel eventually became known as The Empire Strikes Back. But before Lucas began developing the ideas for the second Star Wars movie (particularly the early script drafts with Leigh Beckett), he had recorded his ideas about the overarching Star Wars galaxy with Carol Titelman, who was Lucasfilm's director of publications at the time. And those ideas focused primarily on the main characters - Princess Leia, Han Solo, and even C-3PO - who were introduced in A New Hope.
First off, Lucas expanded on C-3PO's history in the Star Wars saga, and he did so by role-playing as C-3PO when his conversation with Titelman was being recorded (on July 28, 1977). What's interesting about the conversation was that Lucas revealed how C-3PO was created, which Star Wars fans will remember was shown in Lucas' Star Wars: Episode I - The Phantom Menace.
"I'm about 112 years old and have had about forty-three masters. I was made in a robotic factory on the planet Affa, which is one of the Outland Regions in the third sector of the Galactic Empire.
"Before I was assigned to the court of Alderaan, roughly twenty years ago, I was in one of the sub-embassies in the Granicus system. I was working in the embassy for one of the third liaison officers at that time. That's where I really started out. It was a good thirty-seven years before I was actually transferred into protocol. When I started in the embassy, I was one of twelve hundred interpreter droids. I was in the Outland area and there were a lot of strange planets being amassed into the Republic. There was actually a very attrition rate out there, too, because of the strange climates. Many of the droids would fall apart very rapidly. I was lucky to be totally reassembled by a young boy working for a junk dealer. After several years I gained new coverings and became as good as new."
Since these were early notes Lucas had about expanding the Star Wars franchise, it's understandable that certain things were changed down the line or perhaps refined to fit a particular plot point - and one of those subplots was Anakin Skywalker building C-3PO. In the above excerpt, Lucas mentions a young boy working for a junk dealer. In The Phantom Menace, that young boy was Anakin Skywalker and that junk dealer was Watto, a Toydarian who owned both Shmi Skywalker and her son, Anakin.
Of course, this excerpt doesn't say anything about Luke Skywalker's father building C-3PO, but it's clear that aspect of Anakin Skywalker had always been there, even though Lucas perhaps didn't know at the time that he wanted to turn Darth Vader into Luke's father. But this information goes to show just how much Lucas decided on in 1977 - including the idea of Midichlorians in the Star Wars movies - long before work even began on The Empire Strikes Back, and even before Star Wars truly hit its stride at the worldwide box office after getting an expanded release that summer.