Alright, first off a quick summary of the two verb tenses you're asking about.
Past Perfect [had verbed] - This indicates that something happened further in the past than the time I'm referring to. If I was asked "Was that night the first time you drove a car?" I would answer, "No, I had driven once before that." The event I'm referring to (my first time driving) was already in the past when the time already in question (that night) occurred. Past perfect is the correct verb tense in this context.
Past [verbed] - The simple past tense just indicates that something happened before the present. It is used when I am referring to a single event in the past or to multiple concurrent events. For example, "I went to Europe" or "I was in Belgium when they won the World Cup."
I do agree with StoneyB's comment that the question/response you've listed sort of lacks a logical relationship without a story around it. I also agree with FumbleFingers' comment that (again, without context) being out of town "until that moment" seems odd. So, the correct verb tense really depends on what you're trying to say. Presumably it's that you were not in town when this event happened last time. In that case...
How many events in the past are we referring to? Just one. The "last time" this thing happened, during which you happened to be out of town. Therefore the simple past tense is the correct one to use.
"It couldn't have happened, because I was out of town [at] that moment."
If my assumptions to what you were trying to say are incorrect please just edit the question or post a comment to explain that and I'll be happy to edit my answer.
Neither sentence is grammatical English or something that a native would typically say, so it is pointless to argue over what they might mean. I don't see a reason to correct them differently.
“*This would not have been happened” is a passive construction. But happen is not a transitive verb, so it cannot be used in the passive voice. It is likely that the author of this sentence intended to write “This would not have happened”, i.e. the event mentioned previously would not have taken place.
In addition to the previous defect, “*this would have not been happened” is incorrect because the negation cannot be placed where it is. The negation word not is normally placed after the first auxiliary: “this would not have …”.
Furthermore, the second part of the sentence is in the wrong tense. “This would have happened” is a past conditional. The part of the sentence introduced by if is a past hypothetical. It needs to be in the past tense because the time of the action is in the past; in addition, the hypothetical aspect is expressed by a past tense, which means the verb needs to be in the pluperfect tense: “if you had not been there at that time”.
A correct sentence resembling these two incorrect sentences is
This would not have happened if you had not been there at that time.
I can't think of a correct sentence with a different meaning that could be what the author was trying to express.
Best Answer
John Lawler's comment provides a complete answer:
“How could it had happened” is therefore not a grammatical utterance.