The moon, as well as the stars, was shining down on them. is grammatically correct.
The commas are probably considered optional by some writers and grammarians, but they're helpful for indicating that as well as is a preposition here, so I'd say that they're necessary. M-W online shows this: ": in addition to : besides (the coach, as well as the team, is ready)". Merriam-Webster's Dictionary of English Usage recommends using the commas when the first subject is singular.
When as well as is used as a conjunction, it joins two elements without using commas, just as it would were the sentence The moon and the stars were shining down on them. M-W online shows this: ": and in addition : and (brave as well as loyal)".
Many native speakers make what are called "proximity errors". Many usage experts disagree on what "subject-verb agreement" means in sentences that have complex subjects with a singular and a plural element.
He as well as you are right is an example of a proximity error: "Under the 'proximity rule', the verb is governed by the element nearest to it."
See Merriam-Webster's Dictionary of English Usage pages 140-141, as well as, for a thorough discussion of the problem.
There is no definitive answer to your question.
For your example, the correct one uses the preposition "in": "… the people in their forties…".
I cannot conceive of a situation where, in the sentence examples you gave the word "at" could be used correctly.
One of the definitions of in is in the form of a preposition denoting a period or span of time. The word at also comes in the form of a preposition and may also indicate time. However it is specifically to a point in a span of time. For example you can use your example like this:
"Although anyone may need insurance, the ads targeted the people in their forties."
This denotes people who fall in a span of time- between the ages of 40 and 49.
"Although anyone may need insurance, the ads targeted the people at the age of 49."
This sentence has to use at because 49 is a specific point in time.
American usage may sometimes have in and at used interchangeably. However, you should always be mindful of the point of view, the tense, and the literal object to which the proposition refers.
Best Answer
Both seem correct to me though second is clearer. The second sentence may also require some previous reference I think.
The elements are of the right size; The focus is on something that those elements are chosen for.
On the other hand, the first sentence is quite general and focuses more on the elements stating they are of right size.
Compare -