Writing like a native is perfectly possible, but it does take some practice
With speaking, the accent is the stumbling block - too hard to get rid of, and, personally, I can't be bothered.
Even native speakers can have accents, of course. I've known southerners and Californians who've moved to New England. Their regional accents will slowly fade, but they almost never sound like locals. Similarly for British immigrants. My wife still has a trace of a French accent after 15 years in the US, and it's actually gotten stronger since she started speaking French to the kids. But my wife's French accent is still
closer to the local New England accent than a typical southerner's accent would be.
On some level, I don't think is particularly interesting. According to several studies of immigrants to the US, accents start "freezing" as early 6 years old, and they are pretty solidly frozen by puberty. But a faint accent won't prevent you from holding a professional job, becoming a movie actor, or even working as Secretary of State.
As for the larger question...
I've seen quite a few graduate students and post-docs immigrate to the US, and after 5 years or so, they almost all speak intelligently, clearly and colloquially. (Especially if they marry a native speaker.) Writing is actually more of a mixed bag: People who read constantly in their new language usually learn to write just fine. People who don't have time to read tend to be fairly weak in the written register.
And finally, it's important to keep in mind just how much experience a well-read native speaker has—I've been speaking English for decades, every day of my life. I have years of schooling and writing papers. I've read hundreds of millions of words. Of course
somebody from another country is going to have trouble matching that.
So if you ask, "How many years does it take to learn the second language as your native?", my answer is, "It depends on how close you want to get." Do you want to be flawlessly
like a native? Then the answer is probably "never." Would you be satisfied with a faint accent, but otherwise all the linguistic skills of a college-educated native speaker? Then the answer is, "You need to be prepared to pay the same price the natives did, and it took them
over 20 years of immersion, including 17 years of school." Or would you be content with the ability to work at a professional job? Then the answer is, "Around 1,000 to hours to become marginally employable (assuming you're moving between major western European languages), and another 3 to 5 years of full immersion for everything to become truly second nature—provided that you read enough."