For the most part, AFNI is setup for 3D computations. To do things slice wise, it might be simplest to cut the dataset into 1 slice thick pieces, operate on those, then glue them back together. The cutting can be done with program 3dZcutup and the glueing with program 3dZcat. The masking with 3dAutomask (if the slices are not too dim, it should work) plus 3dcalc, and the calculation of the average of nonzero values in the masked dataset with 3dBrickStat.
You'll have to read the help for each of these programs. Or hope that Daniel Glen chimes in with a script.