Here is your script (a) doing what I think you want it to do. It makes a mesh object at each frame, and adds a location keyframe at the frame it was created in script.
import bpy
import math
scn = bpy.context.scene
numY = 10
freq = 1
amp = 1
scale = 1
for numX in range (2, 20):
verts = []
faces = []
for i in range (0, numX):
for j in range (0, numY):
x = scale * i
y = scale * j
z = scale*((amp * math.cos(i * freq)) + (amp * math.sin(j * freq)))
vert = (x, y, z)
verts.append(vert)
count = 0
for i in range (0, numY * (numX - 1)):
if count < numY-1:
A = i
B = i + 1
C = (i + numY) + 1
D = (i + numY)
face = (A, B, C, D)
faces.append(face)
count = count + 1
else:
count = 0
mesh = bpy.data.meshes.new("Wave")
mesh.from_pydata(verts, [], faces)
mesh.update(calc_edges = True)
obj = bpy.data.objects.new("Wave", mesh)
obj.location = (0, 0, 0)
scn.objects.link(obj)
obj.keyframe_insert("location", frame=numX, group="Location")