Titanoboa
There's no snake nowadays which is close to 40ft. long, and even the closest one to it, a record held by the reticulated python, isn't fully substantiated. But, if we turn back the clock a good 65 million years, back when everything was bigger, we find a snake very close to the specification in question - the Titanoboa, a literal giant snake. Now, the reason for a snake this size is very simple - as a boa, it's a constrictor snake and thus needs to be big enough to wrap around and constrict its prey. And since this is 65 million years ago, back when everything was bigger, it's prey was bigger as well.
The blue coloring is simple enough - camouflage. You see, evidence suggests these snakes liked to live in the water, especially warm, swampy areas. (It needed heat, as it's cold-blooded.) Unfortunately, this leaves the caves out of question, unless we changed the caves themselves - perhaps these are very damp caves home to natural hot springs, or something of that nature.
Intelligence isn't really possible. It's head isn't big enough, not to mention that there's nothing a snake could really do with intelligence. There's no reason for natural selection to favor smarter snakes.
The tusks are the largest problem. As a titanoboa is a boa, it constricts its victims, and doesn't need fangs of any sort to poison it's prey. Not to mention that the tusks would just get in the way of the snake trying to move around and/or unhinging its jaw to swallow large prey. Not to mention that tusks aren't something reptile generally have. The closest thing that a boa has to evolve into tusks are teeth, except there's no reason why those teeth would evolve into tusks.
I've done some reading up on Grootslangs, and I've noticed something interesting - the original legend doesn't say that the snake has elephant characteristics - it's just elephant sized. So, given the impracticality of such a thing evolving, I'd argue that this is just a Titanoboa living in the modern day, and leave it at that.