I think the purpose of learning can be defined according to what kind of value we derive from it, and that this value can be of two kinds: intrinsic and instrumental value.
Instrumentally Valuable Learning
I learn X because it will accomplish Y (now or some time in the future).
This kind of learning has instrumental value because it is valuable only insofar as it will accomplish some end. For instance, a student who studies accounting may not enjoy the subject but he nevertheless studies it so that he can pass an exam.
In the context of SE, I know most askers come to that site with a problem that needs to be solved, and once the problem is solved they have no more interest in the knowledge they came seeking.
As you have mentioned, people on SE sites ask questions but often they will not pursue the answer to a question to learn but to quickly solve a problem. This is also an example of transactive memory where the burden of learning is relieved by an immediately applicable answer to some problem.
The "selfishness" you attribute to certain answerers on SE who answer and then leave is more to do with expediency than selfishness, I think. As an aside, there may be even extrinsic motivators at play here like accumulating SE reputation or enjoying acclaim from the community.
But in a broader context, such as secular education, religious instruction, personal interest studies, etc. there is rarely that immediate need to solve a problem, and therefore learning must serve some other purpose.
The above statement can be addressed by returning to our student example mentioned earlier: the same student who studies accounting may toil over his studies for years to pass all his exams, tests and assignments so that he can one day earn a degree making him employable after his studies. Learning can therefore have short and long term instrumental value.
Instrinsically Valuable Learning
I learn X because it is an end-in-itself; I simply enjoy learning X
This kind of learning has intrinsic value because the learner considers the subject he is learning as an end-itself. It is contrasted with the previous kind of learning.
It is possible that somebody learns something simply because they enjoy it or because they consider the learning the summum bonum of life. Philosophy is by definition, the love of wisdom, and its study is an example of this kind of learning.
I would say that this kind of learning is rare. In practical life there are few places where learning is considered intrinsically valuable. Employers and institutions care about how much you have learned only to the extent that you will produce more and/or better quality work for them. Even philosophers must treat their studies as a means to an end sometimes so that they can publish for money and put food on the table. So yes, I would "regard the purpose of learning as a [largely] selfish endeavor".
I hope this adequately addresses the points you have made in your question.