Both are grammatical. The first is also natural. I'm not sure how you intend to use the second.
It means thought about an idea in one's head.
I think we'd never say:
I've been having this idea for some time now. (Present perfect continuous with duration)
And that's why we only use the present perfect tense:
I've had this idea for some time now.
Am I right? Is the main verb "have" a stative verb?
Also, we use "I've had an idea" to mean the idea has come into our mind only recently.
I’ve had an idea. Why don’t we walk into town? (once again present perfect use, but without duration)
To me, the above example indicates that the main verb "have" is
not a stative verb. Because to me, the coming of an idea doesn't seem to be a permanent state. I'm confused:-(